Closed as not planned
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
Validate that overriden method signatures match the base signature (i.e. no narrowing of types)
Fail Cases
class A {
f(p: string | number) {
console.log('A', p);
}
}
class B extends A {
f(p: string) {
console.log('B', p, p.charCodeAt(0));
}
}
const arrayOfA: Array<A> = [new A(), new B()];
for (const item of arrayOfA) {
item.f(123);
}
Pass Cases
class A {
f(p: string | number) {
console.log('A', p);
}
}
class B extends A {
f(p: string | number) { <-- Needs to match base class method signature
console.log('B', p, p.charCodeAt(0));
}
}
const arrayOfA: Array<A> = [new A(), new B()];
for (const item of arrayOfA) {
item.f(123);
}
Additional Info
TS issue was closed as "working as intended" but this is very dangerous, since this breaks some type safety, meaning that this introduces a risk of runtime errors