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
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]'."
The text was updated successfully, but these errors were encountered:
The funny thing is that if you had just done function shallowCopy<T>(t: T, u: T) we would have allowed you to call shallowCopy<Tee>(t, u);, even though that is an error too! That's because we normally treat properties as readonly when considering assignability, even though they aren't in this case. I think #13347 is tracking that sort of issue.
As @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.
TypeScript Version: 2.3.4
Code
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]'."
The text was updated successfully, but these errors were encountered: