我正在将类转换为类型,但我想将该类型转换回类 . 说我有这个班:
export namespace Entities{
export namespace Bar{
export class Foo {
}
}
}
然后我有一个类型的引用:
type F = Entities.Bar.Foo;
有没有办法将F转换回值而不是类型?
就像是:
const V = valueof F;
其中V只是对Foo类的引用 .
(我猜奇怪的是,TypeScript中的类既是类型又是值/表达式) .
我问的原因是因为我有这种情况:
type F = Entities.Bar.Foo;
const x = doSomethingWithClass(Entities.Bar.Foo);
但我想将其转换为这种情况:
type F = Entities.Bar.Foo;
doSomethingWithClass(F);
但那不能编译,我得到:
不能使用F类型作为表达式 .
alternatively ,如果有人知道如何从函数返回一个类型,那可能就足够了:
type F = doSomethingWithClass(Entities.Bar.Foo);