Skip to content

'unknown' is not assignable to type for static API with generic methods #46662

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

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>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions