是否可以获取类型别名的名称?
export type SomeType = { some: 'property' }
我想获取SomeType
-是否可以使用TypeScript做到这一点?
更新-为什么需要此功能
我想要几种这样的类型:
export type SomeType = { some: 'property' }
export type AnotherType = { another: 'property' }
我想创建这些的并集:
export type Types = SomeType | AnotherType
然后,我要创建一个地图类型:
export type TypeMap = {
type: # type/name of type, e.g. SomeType
payload: # object consisting of the properties of the corresponding, type, e.g. { some: string }
}
在此之后,我想例如这样的功能:
function doSomething() => TypeMap {
return # should only allow one of the two definitions in TypeMap
}