I stumbled accross the following scenario recently:
class A {
public m1(x: string | string[]): string | string[] {
return this.m2(x);
}
protected m2(x: string | string[]): string | string[] {
return x;
}
}
class B extends A {
protected m2(x: string[]): string { // no compiler warning
return x.join(',');
}
}
const b = new B();
console.log(b.m1(['a', 'b', 'c'])); // ok
console.log(b.m1('d')); // runtime error
Is this a bug in the TypeScript typing system or intentional? If the latter, how can I change the typing so that the compiler will recognize the problem?