Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useShorthandFunctionType): generic interface type parameters #2020

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ impl Rule for UseShorthandFunctionType {
node,
)?),
)
.build();
.build()
.with_type_parameters(interface_decl.type_parameters());

mutation.replace_node(
AnyJsDeclarationClause::from(interface_decl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ type GenericCallSignature<T> = { (arg: T): T };

// Object type with optional call signature
let optionalCall: { (): number | undefined };

// Generic interface with a call signature
interface GenericInterface<T> {
(value: T): boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type GenericCallSignature<T> = { (arg: T): T };
// Object type with optional call signature
let optionalCall: { (): number | undefined };

// Generic interface with a call signature
interface GenericInterface<T> {
(value: T): boolean;
}

```

# Diagnostics
Expand Down Expand Up @@ -229,6 +234,7 @@ invalid.ts:33:21 lint/style/useShorthandFunctionType FIXABLE ━━━━━
> 33 │ let optionalCall: { (): number | undefined };
│ ^^^^^^^^^^^^^^^^^^^^^^
34 │
35 │ // Generic interface with a call signature

i Types containing only a call signature can be shortened to a function type.

Expand All @@ -239,8 +245,34 @@ invalid.ts:33:21 lint/style/useShorthandFunctionType FIXABLE ━━━━━
33 │ - let·optionalCall:·{·():·number·|·undefined·};
33 │ + let·optionalCall:·()·=>·number·|·undefined;
34 34 │
35 35 │ // Generic interface with a call signature


```

```
invalid.ts:37:2 lint/style/useShorthandFunctionType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! Use a function type instead of a call signature.

35 │ // Generic interface with a call signature
36 │ interface GenericInterface<T> {
> 37 │ (value: T): boolean;
│ ^^^^^^^^^^^^^^^^^^^^
38 │ }
39 │

i Types containing only a call signature can be shortened to a function type.

i Safe fix: Alias a function type instead of using an interface with a call signature.

34 34 │
35 35 │ // Generic interface with a call signature
36 │ - interface·GenericInterface<T>·{
37 │ - → (value:·T):·boolean;
38 │ - }
36 │ + type·GenericInterface<T>·=·(value:·T)·=>·boolean
39 37 │


```
Loading