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
The type of A.prototype includes foo, which is an instance field and not actually present on the prototype.
π Expected behavior
The type of A.prototype should not include instance fields like foo.
Additional information about the issue
My motivation for looking into was trying to write a utility type that differentiated between instance properties and prototype properties in order to generate proper React props types from a class that ignored things that should not be set from the prototype. Right now there is no way at the type level to tell a field from a prototype method at all that I can see.
The text was updated successfully, but these errors were encountered:
justinfagnani
changed the title
Class's prototype property is typed incorrectly
Class's prototype property is typed incorrectly and includes instance properties
Sep 28, 2023
I don't think this should be modelled as an enumerable properties issue. It's more that the instance type of a class is a union (or more accurately an extends type operation) of the instance properties with the prototype's type, but instead the prototype is typed the same as the instance type.
π Search Terms
class prototype typeof instanceof
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?target=9#code/MYGwhgzhAECC0G8BQ1oDMD2HoF5oCYBuFaAIzACcAKASkWgoFMAXAVwoDtoBGQ6AXySCkwDBwgYQjAHQgMAcyqxpABwoZmGgJ4qZmDABpoAcn3HoASy7K1G7bprFR4yTLmKb6zcx0zyFI2N-cys4VS97RkckIA
π» Code
π Actual behavior
The type of
A.prototype
includesfoo
, which is an instance field and not actually present on the prototype.π Expected behavior
The type of
A.prototype
should not include instance fields likefoo
.Additional information about the issue
My motivation for looking into was trying to write a utility type that differentiated between instance properties and prototype properties in order to generate proper React props types from a class that ignored things that should not be set from the prototype. Right now there is no way at the type level to tell a field from a prototype method at all that I can see.
The text was updated successfully, but these errors were encountered: