Classes are a bit weird in typescript, in that they seem to be both actual "things" (functions in this case) and typescript types at same time.
Example:
class Test {
public x: string = 'test';
}
function printX(test: Test) {
console.log(test.x);
}
function createTest() {
return new Test();
}
Notice how I can say printX takes an argument of type Test, but also use Test as a value in createTest() method. So the same symbol "Test" is acting as both a value and a type.
How can I recreate the same kind of construct without using the obvious class keyword?
For example:
function makeTestClass() {
return class Test {
public x: string = 'test';
};
}
const Test = makeTestClass();
function printX(test: Test) {
console.log(test.x);
}
function createTest() {
return new Test();
}
This code will not compile because typescript will think Test is a value, not a type.
So is there some way I can tell typescript Test is actually the magical dual type/value thing you get using the class keyword?