我正在生成使用继承的TypeScript类.每个类都使用静态创建函数,它可能不同.
class A {
static create(arg: string): A {
// use args to create A
return new A()
};
}
class B extends A {
static create(argsForB: number): B {
// use argsForB to create B
return new B()
};
}
Run Code Online (Sandbox Code Playgroud)
由于静态函数无论如何都不应该继承,因此这个错误没有任何意义:
Class static side 'typeof B' incorrectly extends base class static side 'typeof A'.
Types of property 'create' are incompatible.
Type '(argsForB: number) => B' is not assignable to type '(arg: string) => A'.
Types of parameters 'argsForB' and …Run Code Online (Sandbox Code Playgroud) typescript ×1