xenoterracide xenoterracide - 4 months ago 11
TypeScript Question

What type represents a type in typescript?

so given

class Foo {
}

interface TypeProvider() {
type(): ? ;
}

class Bar implements TypeProvider {
type(): ? {
return (Foo);
}
}

class Baz implements TypeProvider {
type(): ? {
return (Bar);
}
}


Foo
is a class but if I'm returning a class from a method, what type do I assign the method signature?

as an aside is
return (Foo)
and
return Foo
the same thing? if they're different I'm not certain I don't want the latter.

Answer

It should be the Foo constructor:

class Bar {
    type(): { new(): Foo } {
        return (Foo);
    }
}

Or:

interface FooConstructor {
    new(): Foo;
}

class Bar {
    type(): FooConstructor {
        return (Foo);
    }
}
Comments