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 realize that spreading a class instance is not desirable.
I also realize (after searching for dupes and reading similar issues for a couple hours) that there are design limitations around TS not tracking own/enumerable properties.
But, from what I understand, it makes a guess and correctly omits methods on classes from the inferred type of spreading an instance of that class. Since getters on classes are also on the prototype, it seems like inconsistent behavior that methods are omitted from the inferred type but get/set accessors are not. Even though the compiler doesn’t really track what properties are own enumerable, it seems like it could use similar heuristics to determine, in this simple case, that the getter won’t be present on the spread object.
P.S. – thanks for your time, and apologies in advance if this does turn out to be a dupe that I couldn’t find 😬
The text was updated successfully, but these errors were encountered:
ghost
added
Duplicate
An existing issue was already created
Bug
A bug in TypeScript
and removed
Duplicate
An existing issue was already created
labels
Aug 7, 2018
TypeScript Version: 3.1.0-dev.20180807
Search Terms:
Code (playground)
Expected behavior:
The inferred type for
phoneClone
should be{}
Actual behavior:
The inferred type for
phoneClone
is{ number: number }
Playground Link: playground
Related Issues:
Discussion
But, from what I understand, it makes a guess and correctly omits methods on classes from the inferred type of spreading an instance of that class. Since getters on classes are also on the prototype, it seems like inconsistent behavior that methods are omitted from the inferred type but get/set accessors are not. Even though the compiler doesn’t really track what properties are own enumerable, it seems like it could use similar heuristics to determine, in this simple case, that the getter won’t be present on the spread object.
P.S. – thanks for your time, and apologies in advance if this does turn out to be a dupe that I couldn’t find 😬
The text was updated successfully, but these errors were encountered: