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 was using super.class(BaseClass) in may cases and it handles typing correctly.
I see: protected class<U extends T>(type: U): U; in the .d.ts file
I was trying out getPrototypeListOf and realized that I was getting all the baseClass as any
And I saw: export function getPrototypeListOf(o: any): any[]; in the .d.ts file
So, creating this issue to potentially improve the typing here to get more accurate types
NOTE: This will assume baseClass has the type (typeof BaseClass1 | typeof BaseClass2)
So, if all my base classes implement a particular function - then this work out quite well
Doing: getPrototypeListOf(ChildClass) as [BaseClass1, BaseClass2] would also work and be more accurate
The text was updated successfully, but these errors were encountered:
Yes this would be helpful in many cases, but I would not want to change the type definition of getPrototypeListOf for this.
The current typing is intended to keep getPrototypeListOf consistent with Object.getPrototypeOf, which returns any.
Crucially, Object.getPrototypeOf and its counterpart Object.setPrototypeOf are inherently not type-safe, because they are intended to work with objects whose type changes dynamically or is not known at compile time (like setting the prototype or getting the prototype to access its properties).
But there could certainly be separate helper types and functions to handle what is not trivial using the core functionality.
In the case you show, since the list of base classes is known in advance, one could even rewrite the code without getPrototypeListOf like this:
I was using
super.class(BaseClass)
in may cases and it handles typing correctly.I see:
protected class<U extends T>(type: U): U;
in the.d.ts
fileI was trying out
getPrototypeListOf
and realized that I was getting all the baseClass asany
And I saw:
export function getPrototypeListOf(o: any): any[];
in the.d.ts
fileSo, creating this issue to potentially improve the typing here to get more accurate types
PS: I have no idea if it is possible at all :)
I did try this:
NOTE: This will assume
baseClass
has the type(typeof BaseClass1 | typeof BaseClass2)
So, if all my base classes implement a particular function - then this work out quite well
Doing:
getPrototypeListOf(ChildClass) as [BaseClass1, BaseClass2]
would also work and be more accurateThe text was updated successfully, but these errors were encountered: