Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OverrideProperties type #597

Merged
merged 9 commits into from Apr 23, 2023

Conversation

nidomiro
Copy link
Contributor

Adds the OverrideProperties type.
It is basically a Merge with the constraint, that you can only override properties.

Example:

type Foo = {
	a: string
	b: string
}
type Bar = OverrideProperties<Foo, { b: number }>
//=> type Bar = { a: string, b: number }

type Baz = OverrideProperties<Foo, { c: number }>
// error TS2559: Type '{ c: number; }' has no properties in common with type 'Partial{ a: unknown; b: unknown; }>'.

@nidomiro nidomiro marked this pull request as ready for review April 17, 2023 07:53
@sindresorhus
Copy link
Owner

Thanks for contributing. Make sure you adhere to: https://github.com/sindresorhus/type-fest/blob/main/.github/contributing.md#submitting-a-new-type

@nidomiro
Copy link
Contributor Author

sure, I thought I did.
Maybe you can point out what I'm missing?

@sindresorhus
Copy link
Owner

Please help review the other open pull requests. If there are no open pull requests, provide some feedback on some of the open issues.

It takes a lot of effort to review all new pull requests. If people submitting new types could also help review other pull requests, it would lighten my load. 🙏

type Baz = OverrideProperties<Foo, {c: number}>
// error TS2559: Type '{c: number}' has no properties in common with type 'Partial{a: unknown; b: unknown}>'.
```
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add categories. See other types for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see that, thanks for pointing out

import type {Merge} from './merge';

/**
Override existing property types in TOriginal with the types in TOverride.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should match the readme description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I also rearranged the entry in the readme to be right after the merge types.

source/override-properties.d.ts Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit c365837 into sindresorhus:main Apr 23, 2023
7 checks passed
@sindresorhus
Copy link
Owner

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants