-
Notifications
You must be signed in to change notification settings - Fork 12.8k
The property prototype of an abstract constructor type is unavoidably of type any. #56801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Possible (ugly) workaround: |
(@fatcerberus Instead of trying to use type AAbstractConstructor = abstract new () => A;
interface AAbstractConstructorRemedied extends AAbstractConstructor {
prototype: A;
} This will have the |
Thanks for the workaround @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. // error
interface WithPrototype<Class extends abstract new (...args: any) => any> extends Class {
prototype: InstanceType<Class>
}
type AbstractConstructorWithPrototype<Class extends abstract new (...args: any) => any> =
WithPrototype<abstract new (...args: ConstructorParameters<Class>) => InstanceType<Class>>; But the interface declaration errors. Thanks anyway for the suggestion. |
I messed around with it for a bit and managed to make it work like this: type AbstractConstructor<Class extends abstract new (...args: any) => any> =
abstract new (...args: ConstructorParameters<Class>) => InstanceType<Class>;
interface AbstractConstructorWithPrototype<Class extends abstract new (...args: any) => any> extends AbstractConstructor<Class> {
prototype: InstanceType<Class>
} The fact that the "hidden" prototype is of type |
π Search Terms
abstract constructor prototype type any
π Version & Regression Information
Latest version as of today.
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAECC0G8C+AoFAXAngBwKZwGEB7AOwnQCcBXYdIi6AXmhNwHcAKASiYD44A3Gix5CpctVr0AkiXS4KEXLQCWpJtA6tOPRv1g8AZImjYKROiNwAuONCRCUKuQoBmYYPljEylGnQoAJVwAW1wAExUIxBRoOJZ2bltYIXjTc0scG0EUVGEsuFgAIwkPdB8Jf3oNMBLKMoSdPhynFwp3TzhpEOwiKBUikFwKvykGBFj42tLaRqTBaAB6RegFcwpJuLMLCyzkoTz80QB9AEYNDisiVzguAG0Acm3MvAeAXQElleB6CmV0ZJHfDHABMGm84lGAUez12rw+X2gzh+FD+tFsYBImCB0GOAGZwSNJAFZPJFP81CQYRk4bh3p9lkiSCi0QDoJjsRgCscACyEyHE+jBMKRCLUnZWemIln-QFck4AVnBxRm5QFVQo4pedIRjORv1l7KxKCAA
π» Code
π Actual behavior
There's no way of making the type of
prototype
something other thanany
, not even with an intersection.π Expected behavior
A way to make the type of
prototype
something other thanany
. It seems that constructor types have a hiddenprototype
of typeany
. Shouldn't it be of typeunknown
so that at least the intersection works? (or wouldn't it be better for it to be the same type asInstanceType
directly?)Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: