Disallow argument mismatch between interface and implementation
- Dominant language
- TypeScript
- Stars
- 50
- Forks
- 26
- Avg merge
- 7h 10m
- Merged PRs (30d)
- 37
Description
Currently, the compiler will allow the following program:
```typescript
export interface IAdder {
add(a: number, b: number): number;
}
export class Adder implements IAdder {
public add(a1: number, b1: number): number {
return a1 + b1;
}
}
```
Notice the argument names in `Adder.add` are different from `IAdder.add`.
This results in an incompatibility between the `IAdder` interface and the `Adder` class in python. See:
- https://github.com/aws/aws-cdk/issues/27852
- https://github.com/aws/jsii/issues/4541
- https://github.com/aws/aws-cdk/issues/21099
- https://github.com/aws/aws-cdk/issues/20125
We should have the compiler enforce that functions in implementations (or subclasses) use the same argument names as the parent.
### Notes
- Unless we roll out a new major version, we cannot start enforcing this on existing projects because the fix would have to be argument renaming, and this [would be a breaking change](https://github.com/aws/jsii/pull/2937). In order to maintain backwards compatibility and stop the proliferation of this mistake, we need to provide an allow list mechanism to ignore existing violations, as well as a feature toggle to activate this validation. In the next major version of the compiler, we can remove these provisions and start enforcing it.
- It would be nice to resurrect and merge https://github.com/aws/jsii/pull/2937 as well, as this would protect us against accidental renaming, either in an attempt to fix the inconsistency, or just an ad-hoc decision to rename some arguments.
Contributor guide
Research direction
No source files or tests are named. Start by tracing the compiler's validation of interface implementations and subclasses, then review the compatibility requirements in the issue and the historical jsii PR #2937. Done means argument-name mismatches are validated with an allow list and feature toggle, while existing projects remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100