admin管理员组

文章数量:1530845

Property ‘zeroValue’ has no initializer and is not definitely assigned in the constructor.
Property ‘add’ has no initializer and is not definitely assigned in the constructor.

解决方法一

TypeScript的新特性所有定义的值必须赋予,初始值
我们设置其值 是可选

zeroValue?: T;
    add?: (x: T, y: T) => T

解决方法二

创建构造方法

constructor(zeroValue: T) {
        this.zeroValue = zeroValue
    }

本文标签: 报错typescript泛型类