Description
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
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about - couldn't find anything relevant
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Constructable<T> {
new (...args: any[]): T;
myStaticMethod<P extends any>(param: P): void; // why is this treated as P extends unknown ?
}
class SomeClass {
static myStaticMethod<P extends string>(param: P): void { }
}
function fn(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>
.