您好,我有一个提供通用类型的类,可以检查该值是否是此Type的实例或类型,但是它不起作用,我无法想象如何解决此问题:>
export class Controller<T> {
private controllers: any[];
public registerControllersInContainer = () => {
for (let controller of this.controllers) {
const validate = isClass<T>(controller);
if (validate) container.registerSingleton<T>('Controllers', controller);
}
};
}
我尝试一下:
export const isClass = <T>(object: any): object is T => {
if (object as T) {
return true;
}
return false;
};
但始终返回true,instanceof和typeof不起作用:“ T”仅引用类型,但在此处用作值。ts(2693)