在TypeScript中,有没有办法键入以下fn函数,以便TypeScript仍然知道result的类型是'hello' const hello = 'hello' // hello is of type'hello'
const result = fn(hello) // result is of type unknown 对于泛
我很难理解如何在TypesScript中实现泛型。我知道有许多类似的问题,但似乎没有解决我的用例。(有,但我有一个不同的关注点,即函数的输出与函数的输入类型相同)
我希望有这样一个函数,其中泛型仅限于两种不同的类型,而输出与输入的类型相同。should know that param can only be a