在TypeScript中,有没有办法键入以下fn函数,以便TypeScript仍然知道result的类型是'hello' const hello = 'hello' // hello is of type'hello'
const result = fn(hello) // result is of type unknow
T>' requires 1 type argument(s).
a = new A<'test'>({ name: 'test' }),;
有没有办法告诉typescript,a: A的泛型类型应该是创建a时使用的类型?我猜我在这里打乱了一些OOP概念,并试图获得一些在概念层面上毫无意义的东西,但如果不是这样,那么解决这个问题
在下面的示例中,我希望确保返回的类型与泛型函数中给定的泛型类型相对应。不幸的是,当使用result instanceof T时,TypeScript报告以下错误:error TS2693: 'T' only refers to a type, but is being used有没有办法在运行时检查对象的类型是否对应于泛型类型?