You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
I have the following AllKeys type that returns all the keys of union type.
typeAllKeys<T>=Textendsunknown ? keyofT: never;
Now, I'm unsure why keyof T is not assignable to AllKeys<T>, whereas AllKeys<T> is assignable to keyof T. Shouldn't the opposite of this be true?
typeAllKeys<T>=Textendsunknown ? keyofT: never;// KeysOfUnion<T> should not be assignable to keyof TtypeWithKeyOfConstraint<T,KextendskeyofT>=unknown;typeTest1<T>=WithKeyOfConstraint<T,AllKeys<T>>;// should error but doesn't// keyof T should be assignable to KeysOfUnion<T>typeWithAllKeysConstraint<T,KextendsAllKeys<T>>=unknown;typeTest2<T>=WithAllKeysConstraint<T,keyofT>;// shouldn't error but does
When it comes to this specific case you can read around the comment I touched here: 69e4dcf . In general, the containing function is responsible for a lot of the assignability rules so if you are interested in how TS breaks down through the relationships you can read about it there.
That said, this PR wasn't correct and I already have closed it 😅
Acknowledgement
Comment
I have the following
AllKeys
type that returns all the keys of union type.Now, I'm unsure why
keyof T
is not assignable toAllKeys<T>
, whereasAllKeys<T>
is assignable tokeyof T
. Shouldn't the opposite of this be true?Playground
Would love to understand how is assignability b/w two uninstantiated generics checked?
The text was updated successfully, but these errors were encountered: