-
Notifications
You must be signed in to change notification settings - Fork 11
Basic Usage
Roman Jámbor edited this page Oct 22, 2021
·
2 revisions
import { getType } from "tst-reflect";
function printTypeProperties<TType>() {
const type = getType<TType>(); // <--- getting type of generic type in runtime :)
console.log(type.getProperties().map(prop => prop.name + ": " + prop.type.name).join("\n"));
}
interface SomeType {
foo: string;
bar: number;
baz: Date;
}
class SomeImpl implements SomeType {
foo: string;
bar: number;
baz: Date;
}
printTypeProperties<SomeType>();
const interfaceType = getType<SomeType>();
const classType = getType<SomeImpl>();
if (classType.isAssignableTo(interfaceType)) { // true
console.log("Class SomeImpl implements SomeType interface.");
}