【问题标题】:How create instance of generic type parameter in type script [duplicate]如何在类型脚本中创建泛型类型参数的实例 [重复]
【发布时间】:2018-08-08 05:59:41
【问题描述】:

我有一个像这样的通用函数:

export function f<T >(json: Object): T {
return new T()

}

但我在 com'T' only refers to a type, but is being used as a value here. 时收到此错误

我应该如何处理?

【问题讨论】:

标签: node.js typescript generics


【解决方案1】:

试试这个

export function f<T>(arg: T): T {
    return arg;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 2014-05-31
    相关资源
    最近更新 更多