I'm encountering an issue with my subclass that extends an abstract superclass in a separate file. The problem arises in the code snippet within implementation.ts
, where TS typecheck fails for doStrangeThing()
since I have to re-declare the parameter types (string, IComplexOptions). Is there a way to avoid this additional import and repetitive declaration? Any suggestions on how to achieve this?
It seems logical that the compiler should be able to infer the method signature from the superclass, especially if it's abstract, or at the very least consider it as the default if it's missing. Am I overlooking any possible solutions to address this issue (excluding complexities like method overloading or union types)? Is there a method to extract the parameters, provide hints to inherit the signature from the super, or some other approach?
//
// baseClasses.ts
//
import {IComplexOptions} from './foo';
abstract class Animal {
abstract name: string;
abstract doStrangeThing(action:string, options:IComplexOptions): void;
}
//
// implementation.ts
//
import {Animal} from './baseClasses';
class Rhino extends Animal {
name = "Rhino";
doStrangeThing(action, options) { // <== TS error here, implicit 'any'
}
}