feat(lint): implement useUnifiedTypeSignature rule#6320
feat(lint): implement useUnifiedTypeSignature rule#6320ematipico merged 2 commits intobiomejs:mainfrom
useUnifiedTypeSignature rule#6320Conversation
80d7883 to
61aae18
Compare
CodSpeed Performance ReportMerging #6320 will not alter performanceComparing Summary
|
dyc3
left a comment
There was a problem hiding this comment.
I'm impressed! To say that this was a tough one would be an understatement.
As always, impeccable work! As the 2.0 release is immanent, we'll wait to merge this for 2.1.
dyc3
left a comment
There was a problem hiding this comment.
Blocking to prevent accidental merges.
|
|
||
| if required_self_len > other.len() + 1 { | ||
| // If the difference between signatures is more than 1, | ||
| // means those additional parameters are cross-connected, |
There was a problem hiding this comment.
What does cross-connected mean? That might be something to clarify.
There was a problem hiding this comment.
Feel free to suggest a better description.
Basically when a difference between signatures is one parameter, we can potentially make it optional and merge signatures:
function test(x: number): void;
function test(x: number, y: string): void;
// -->
function test(x: number, y?: string): void;But when the difference between signatures exceeds one parameter, we can't do it, because those parameters are either not specified or specified together.
function test(): void;
function test(x: number, y: string): void;
// we can't merge them this way, because it makes test(1) a valid call:
function test(x?: number, y?: string): void;There was a problem hiding this comment.
Thanks! Could you leave an example such as that in the comment?
There was a problem hiding this comment.
Sure. Rephrased the comment and added an example.
| /// Trait for comparing types to determine if they are equal. | ||
| /// This can potentially be instead generated in the same process as the AST node generation. | ||
| /// Basically it compares only AST ignoring node metadata like comments, whitespace, etc. | ||
| trait TypeEquals { |
🦋 Changeset detectedLatest commit: 90830a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e2d80d1 to
97d8ba6
Compare
97d8ba6 to
4de0847
Compare
|
Rebased. |
ematipico
left a comment
There was a problem hiding this comment.
I haven't checked the implementation, however we should update the changeset
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
|
@ematipico sure, updated. |
Summary
Added the new rule
useUnifiedTypeSignature, which disallows overload signatures that can be unified into a single signature.Overload signatures that can be merged into a single signature are redundant and should be avoided. This rule helps simplify function signatures by combining overloads by making parameters optional and/or using type unions.
Example (Invalid): Overload signatures that can be unified:
Example (Valid): Unified signatures:
Example (Valid): Different return types cannot be merged:
Test Plan
Tests are included
Notes
nursery/useUnifiedTypeSignature-typescript-eslint/unified-signatures#50, only adjacent overload signatures are checked.Closes #50