Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Class Reference

Flow has the concept that you can write the following type definition to refer to a class that inherits from another class: function getHouseClass(): Class<House> {}

This refers to the class, not an instance of the class.

Is there a similar concept in Typescript? Class<House> apparently doesn't work in TS.

Thanks!

like image 747
vardump Avatar asked Oct 30 '25 15:10

vardump


1 Answers

I think @toskv is correct. If you look at this comparison between the two (below 'Accessing the type of a Class' headline):

Flow

class Test {};
type TestType = Class<Test>;
// This should be equivalent to (if you can confirm, please send a PR):
type TestType = typeof Test;

TypeScript

class Test {};
type TestType = typeof Test;

The following should then be the same:

function getHouseClass(): typeof House { return House; }
like image 151
Arg0n Avatar answered Nov 03 '25 22:11

Arg0n