Quantcast
Viewing latest article 40
Browse Latest Browse All 43

Class to Instance Registry Typing in TypeScript

I'm trying to use classes as input values to a registry method where the return value is a cached instance of that instance. However I do not find a way to make this type safe.

What I want is something like this:

class MyRegistry {  getInstance<T, C extends Class<T>>(cls: C): T;}let x: MyThing = registry.getInstance(MyThing);

Is there a way to make this work? I'm aware there are ways to type out newables but I cannot find a way to make the return value concrete.


Viewing latest article 40
Browse Latest Browse All 43

Trending Articles