TypeScript:隐式泛型值类型?

时间:2019-01-28 12:09:08

标签: typescript generics types implicit value-type

我希望声明一个通用函数,该函数可以解析为值类型,而不是所传递参数的完整类型集。

getProp<V>(value :V) : V
{ return value; }


// This has return type <string>, but I want return type <"test">
getProp("test");

// This has correct return type, but require explicit generic parameter.
// Also, I have several generic parameters, and then I have to state them all...
getProp<"test">("test");

0 个答案:

没有答案