【问题标题】:Generic Type Inheritance in TypeScriptTypeScript 中的泛型类型继承
【发布时间】:2020-01-05 06:53:17
【问题描述】:

我对 Typescript 还是很陌生。请帮我解释一下下面的代码 sn-p 有什么问题。

interface ICalcValue {

    readonly IsNumber : boolean;

    readonly : IsString : boolean;

}



interface ICalcValue<T> extends ICalcValue {

    readonly T Value;

}

【问题讨论】:

  • 至少你能提供一些关于你在编译时遇到的错误的细节。

标签: typescript inheritance typescript-generics


【解决方案1】:

不同于其他语言(例如 C#)。在打字稿中不可能有两种仅通过类型参数不同的类型。您将需要为接口使用不同的名称(修复其他小的语法错误):

interface ICalcValueBase {

    readonly IsNumber: boolean;

    readonly IsString: boolean;

}

interface ICalcValue<T> extends ICalcValueBase {

    readonly Value: T;

}

play

【讨论】:

    猜你喜欢
    • 2020-12-01
    • 2018-09-27
    • 2015-09-15
    • 2018-08-01
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多