I have the following;
import { reflect } from 'typescript-rtti';
interface Entity {
id: string
}
interface User extends Entity {
name: string;
}
class A<T extends Entity> {
private instanceName: string;
public constructor() {
this.instanceName = reflect<T>().as('class').reflectedClass.getOwnProperty('name');
}
public getInstanceName(): string { return this.instanceName; }
}
const a = new A<User>();
console.log(a.instanceName);
Basically, I expected instanceName to be User but got Object.
What's the proper way to get the name of the generic type passed into the class?
I can't do reflect(T) as that reports the error: "TS2693: T only refers to a type, but is being used as a value here."
I have the following;
Basically, I expected
instanceNameto beUserbut gotObject.What's the proper way to get the name of the generic type passed into the class?
I can't do
reflect(T)as that reports the error: "TS2693: T only refers to a type, but is being used as a value here."