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 am trying to have an interface (Constructable) for the static API of a class (SomeClass), which I want to be able to pass to some function (fn).
I have some static methods in the static API, that should allow to pass parameters with generic types.
I can't get the generic types to be assignable to one another.
interfaceConstructable<T>{new(...args: any[]): T;myStaticMethod<Pextendsany>(param: P): void;// why is this treated as P extends unknown ?}classSomeClass{staticmyStaticMethod<Pextendsstring>(param: P): void{}}functionfn(ctor: Constructable<SomeClass>): void{}fn(SomeClass);
🙁 Actual behavior
I cannot call fn with SomeClass because the generic type "'unknown' is not assignable to type string". This also does not work if I change the Constructable interface to have this method: myStaticMethod<P>(param: P): void; (generic parameter does not extend any). Then the error is simply "'P' is not assignable to type string".
🙂 Expected behavior
I expected that SomeClass is assignable to the type Constructable<SomeClass>.
The text was updated successfully, but these errors were encountered:
Bug Report
I am trying to have an interface (
Constructable
) for the static API of a class (SomeClass
), which I want to be able to pass to some function (fn
).I have some static methods in the static API, that should allow to pass parameters with generic types.
I can't get the generic types to be assignable to one another.
🔎 Search Terms
'unknown' is not assignable to type
Possibly related to #45255
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
I cannot call
fn
withSomeClass
because the generic type "'unknown' is not assignable to type string". This also does not work if I change theConstructable
interface to have this method:myStaticMethod<P>(param: P): void;
(generic parameter does not extend any). Then the error is simply "'P' is not assignable to type string".🙂 Expected behavior
I expected that
SomeClass
is assignable to the typeConstructable<SomeClass>
.The text was updated successfully, but these errors were encountered: