-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
feat(58561): Allow leading underscore for types to bypass noUnusedLocals warning #58884
Open
a-tarasyuk
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
a-tarasyuk:feat/58561
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−0
Open
Changes from all commits
Commits
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 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
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/unusedTypeDeclarations.errors.txt
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
unusedTypeDeclarations.ts(1,6): error TS6196: 'T1' is declared but never used. | ||
|
||
|
||
==== unusedTypeDeclarations.ts (1 errors) ==== | ||
type T1 = number; // error | ||
~~ | ||
!!! error TS6196: 'T1' is declared but never used. | ||
type _T2 = number; // ok | ||
|
||
export {}; | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] //// | ||
|
||
//// [unusedTypeDeclarations.ts] | ||
type T1 = number; // error | ||
type _T2 = number; // ok | ||
|
||
export {}; | ||
|
||
|
||
//// [unusedTypeDeclarations.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] //// | ||
|
||
=== unusedTypeDeclarations.ts === | ||
type T1 = number; // error | ||
>T1 : Symbol(T1, Decl(unusedTypeDeclarations.ts, 0, 0)) | ||
|
||
type _T2 = number; // ok | ||
>_T2 : Symbol(_T2, Decl(unusedTypeDeclarations.ts, 0, 17)) | ||
|
||
export {}; | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/compiler/unusedTypeDeclarations.ts] //// | ||
|
||
=== unusedTypeDeclarations.ts === | ||
type T1 = number; // error | ||
>T1 : number | ||
> : ^^^^^^ | ||
|
||
type _T2 = number; // ok | ||
>_T2 : number | ||
> : ^^^^^^ | ||
|
||
export {}; | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @noUnusedLocals: true | ||
|
||
type T1 = number; // error | ||
type _T2 = number; // ok | ||
|
||
export {}; |
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.
At some level, I wonder if we should just be checking
isIdentifierThatStartsWithUnderscore
for all declarations, rather than special casing a few kinds. What declarations are we actually missing here?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.
I think this is open to discussion. The fix shouldn't require significant work... What do you think, @RyanCavanaugh?
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.
I guess it's sort of nonsensical to do this for enum members and properties and so on; after all, their names are important.
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.
@jakebailey What are your thoughts on the following list? Should we add or exclude any additional declarations?
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.
I would say any declaration that can be a child of a
Block
orSourceFile
orModule
, etc, if that makes sense. So basically not enum members or properties. Not sure we have a list of that variety, though...