-
Notifications
You must be signed in to change notification settings - Fork 888
Check for covariant parameters in interface implementations #4325
Comments
Same as in #4175 - what bugs would this actually catch? Another example of a place where this covariance allows a stricter parameter type in the implementing class: interface TestInterface {
Method(text: string | undefined): void;
}
class TestClass implements TestInterface {
public Method(): void { // Warning: should have a text: string|undefined parameter
console.log("zoinks");
}
} ...but if either issue's rule were to be created, users would end up just adding unnecessary types to parameters or adding in unused parameters with names like Unless there's a good reason (e.g. a lot of caught bugs) to enable this rule, it seems like something that would be better off in a third party package. That'd let you iterate on this idea without having to be locked into the TSLint release cycle and review system. Thoughts? |
I discovered this situation after enabling the strict-type-predicates rule locally. It resulted in a warning that the null check for It turns out the method was implemented to handle |
Rule Suggestion
Is your rule for a general problem or is it specific to your development style?
General.
What does your suggested rule do?
Report a warning when a typescript method implements an interface, but one or more parameters of the implementing method have covariant types with respect to the interface definition.
List several examples where your rule could be used
Additional context
This is a subset of the functionality in #4175.
The compiler behavior is described in microsoft/TypeScript#27523.
The text was updated successfully, but these errors were encountered: