1
abstract class A {

}

class B extends A {
    public static readonly TYPE = "A";
}

interface forValue<T extends { TYPE: string }> {
    type: T["TYPE"]
}

The above works perfectly fine, now I want to be able to use this without having to do: forValue<typeof (T extends A)> for every subclass of A, T.

So I want something like this:

type forClass<T extends A> = forValue<typeof T>;

But I get the error TS2693: 'T' only refers to a type, but is being used as a value here.. I don't think typescript is picking up the typeof before T. If I replaced T with B, i.e:

type forClass<T extends A> = forValue<typeof B>;

It works fine.

Is this a bug?

Tobiq
  • 2,489
  • 19
  • 38

0 Answers0