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
{{ message }}
Repository navigation
keyof does not work with extends in generic type argument. #16740
Expected behavior:
I would expect this function to compile, since U is a sub class of T and U's keys are presumably treated as superset of T's keys. Each key of T should be a key of U as well.
Actual behavior:
TypeScript reports the following error: "Type 'T[keyof T]' is not assignable to type 'U[keyof T]'."
As Andy (Andrewkraft) (@Andy-MS) is pointing out, this is working as intended. You are right that each key of T is a key of U as well, but a U[K] may be a subtype of the corresponding T[K] for the same K, and T[K] is therefore not assignable to U[K].
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
ahejlsberg commentedon Jun 27, 2017
As Andy (Andrewkraft) (@Andy-MS) is pointing out, this is working as intended. You are right that each key of
Tis a key ofUas well, but aU[K]may be a subtype of the correspondingT[K]for the sameK, andT[K]is therefore not assignable toU[K].mhegazy commentedon Aug 17, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.