-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [no-base-to-string] handle more robustly when multiple toString()
declarations are present for a type
#10432
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
Merged
JoshuaKGoldberg
merged 9 commits into
typescript-eslint:main
from
kirkwaiblinger:spread-element
Dec 7, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e224e60
remove confusing spread element test cases
kirkwaiblinger 1fc3f23
fix intersection checking
kirkwaiblinger 01f6a24
fix for old versions of TS
kirkwaiblinger 132bb4f
lintfix
kirkwaiblinger 2309fe3
readability
kirkwaiblinger d2b7ca7
isTypeParameter comment
kirkwaiblinger 2a943bd
derp
kirkwaiblinger dfd3b70
ignored types
kirkwaiblinger f323fdc
expression
kirkwaiblinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,16 +135,20 @@ tag\`\${{}}\`; | |
"'' += new URL();", | ||
"'' += new URLSearchParams();", | ||
` | ||
let numbers = [1, 2, 3]; | ||
String(...a); | ||
`, | ||
` | ||
Number(1); | ||
`, | ||
{ | ||
code: 'String(/regex/);', | ||
options: [{ ignoredTypeNames: ['RegExp'] }], | ||
}, | ||
{ | ||
code: ` | ||
type Foo = { a: string } | { b: string }; | ||
declare const foo: Foo; | ||
String(foo); | ||
`, | ||
options: [{ ignoredTypeNames: ['Foo'] }], | ||
}, | ||
` | ||
function String(value) { | ||
return value; | ||
|
@@ -215,6 +219,46 @@ class Foo {} | |
declare const tuple: [string] & [Foo]; | ||
tuple.join(''); | ||
`, | ||
// don't bother trying to interpret spread args. | ||
` | ||
let objects = [{}, {}]; | ||
String(...objects); | ||
`, | ||
// https://github.com/typescript-eslint/typescript-eslint/issues/8585 | ||
` | ||
type Constructable<Entity> = abstract new (...args: any[]) => Entity; | ||
|
||
interface GuildChannel { | ||
toString(): \`<#\${string}>\`; | ||
} | ||
|
||
declare const foo: Constructable<GuildChannel & { bar: 1 }>; | ||
class ExtendedGuildChannel extends foo {} | ||
declare const bb: ExtendedGuildChannel; | ||
bb.toString(); | ||
`, | ||
// https://github.com/typescript-eslint/typescript-eslint/issues/8585 with intersection order reversed. | ||
` | ||
type Constructable<Entity> = abstract new (...args: any[]) => Entity; | ||
|
||
interface GuildChannel { | ||
toString(): \`<#\${string}>\`; | ||
} | ||
|
||
declare const foo: Constructable<{ bar: 1 } & GuildChannel>; | ||
class ExtendedGuildChannel extends foo {} | ||
declare const bb: ExtendedGuildChannel; | ||
bb.toString(); | ||
`, | ||
` | ||
function foo<T>(x: T) { | ||
String(x); | ||
} | ||
`, | ||
` | ||
declare const u: unknown; | ||
String(u); | ||
`, | ||
], | ||
invalid: [ | ||
{ | ||
|
@@ -277,21 +321,6 @@ tuple.join(''); | |
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
let objects = [{}, {}]; | ||
String(...objects); | ||
`, | ||
errors: [ | ||
{ | ||
data: { | ||
certainty: 'will', | ||
name: '...objects', | ||
}, | ||
messageId: 'baseToString', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "'' += {};", | ||
errors: [ | ||
|
@@ -682,13 +711,63 @@ declare const foo: Bar & Foo; | |
errors: [ | ||
{ | ||
data: { | ||
certainty: 'will', | ||
certainty: 'may', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just an existing bug of imprecise handling of generics. |
||
name: 'array', | ||
}, | ||
messageId: 'baseArrayJoin', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
type Bar = Record<string, string>; | ||
function foo<T extends string | Bar>(array: T[]) { | ||
array[0].toString(); | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
data: { | ||
certainty: 'may', | ||
name: 'array[0]', | ||
}, | ||
messageId: 'baseToString', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
type Bar = Record<string, string>; | ||
function foo<T extends string | Bar>(value: T) { | ||
value.toString(); | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
data: { | ||
certainty: 'may', | ||
name: 'value', | ||
}, | ||
messageId: 'baseToString', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
type Bar = Record<string, string>; | ||
declare const foo: Bar | string; | ||
foo.toString(); | ||
`, | ||
errors: [ | ||
{ | ||
data: { | ||
certainty: 'may', | ||
name: 'foo', | ||
}, | ||
messageId: 'baseToString', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
type Bar = Record<string, string>; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this relevant, you might ask? Because it affects the order in which the overloads are declared (and therefore resolved), at least for TS < 5.4.
(playground)
but this errors
(playground)