TypeScript子类不能继承父级的方法类型定义

时间:2019-10-24 03:14:01

标签: typescript typescript-typings typescript-generics

我在class中有TypeScript继承问题。我的子class不会继承其parent类的方法定义。

class Animal<T = any> {
    public say(a: T) {
        console.log(a);
    }

    walk(s: number) {

    }
}

class Dog extends Animal<string> {
    // a2 has a type of `any` instead of `string`
    say(a2) {

    }
    // s2 recognized as `any`, which should be `number` from parent class definition
    walk(s2) {

    }
}

0 个答案:

没有答案