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
The property prototype of an abstract constructor type is unavoidably of type any.Β #56801
There's no way of making the type of prototype something other than any, not even with an intersection.
π Expected behavior
A way to make the type of prototype something other than any. It seems that constructor types have a hidden prototype of type any. Shouldn't it be of type unknown so that at least the intersection works? (or wouldn't it be better for it to be the same type as InstanceType directly?)
The fact that the "hidden" prototype is of type any instead of (at least) unknown, it's a little bit odd, but since there's a work around, I'll close this issue.
Activity
fatcerberus commentedon Dec 15, 2023
Possible (ugly) workaround:
Omit<new () => A, "prototype"> & { prototype: A }jcalz commentedon Dec 15, 2023
(Bruce Pascoe (@fatcerberus)
Omitloses the construct signature)Instead of trying to use
abstract newinside an object type, you can do this:This will have the
prototypeproperty you care about while maintaining theabstractness of the constructorPlayground link
miguel-leon commentedon Dec 15, 2023
Thanks for the workaround Joe Calzaretta (@jcalz), silly me I didn't think of this while coming up with a minimal reproduction.
The thing is, the type that returns the construct signature is a parametric type.
I just tried
playground
But the interface declaration errors.
Do you think that as a parametric type then it becomes unavoidable? π
Or maybe is there another workaround?
Thanks anyway for the suggestion.
miguel-leon commentedon Dec 16, 2023
I messed around with it for a bit and managed to make it work like this:
playground
The fact that the "hidden" prototype is of type
anyinstead of (at least)unknown, it's a little bit odd, but since there's a work around, I'll close this issue.