-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
DistributedOmit may not need to constraint the second type argument #866
Comments
Why? |
we were build a component wrapper which disallow passing some specific props directly the here is the demo import type { DistributedOmit } from 'type-fest';
type DistributedOmitLoose<
ObjectType,
KeyType extends keyof any,
> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
type SomeComponentPropsTypeWithControl = {
onChange: (value: any) => void;
controllable: true;
};
type SomeComponentPropsTypeWithoutControl = {
controllable: false;
};
type SomeComponentProps =
| SomeComponentPropsTypeWithoutControl
| SomeComponentPropsTypeWithControl;
// works
type Result1 = Omit<SomeComponentProps, 'value'>;
// works and exactly what i want
type Result2 =
| Omit<SomeComponentPropsTypeWithControl, 'value'>
| Omit<SomeComponentPropsTypeWithoutControl, 'value'>;
// loose constraint. works. same as Result2
type Result3 = DistributedOmitLoose<SomeComponentProps, 'value'>;
// DistributedOmit from package
// Type '"value"' does not satisfy the constraint 'keyof SomeComponentPropsTypeWithoutControl'
type Result4 = DistributedOmit<SomeComponentProps, 'value'>; IMO, when omitting properties from a interface, there's no need to check if they were actually exist. |
I do agree that it would be nice to support this use-case. One downside is that it then would not be able to auto-complete the key. |
@henriqueinonhe Thoughts? |
I have a similar issue with The simple following type does not work type ReplaceKey<T, V> = T extends { key: string } ? DistributedOmit<T, 'key'> & { key: V } : T I get the following error
|
This is fantastic, thank you. In a heavily abstracted layer of framework code, it's most often not possible to get autocompletion on Omit anyway. This is a great drop in replacement for DistributedOmit. |
since typescript omit is something like this
could we change the constraint
extends KeysOfUnion<ObjectType>
inDistributedOmit
as same ?Upvote & Fund
The text was updated successfully, but these errors were encountered: