-
Notifications
You must be signed in to change notification settings - Fork 13k
feat(58561): Allow leading underscore for types to bypass noUnusedLocals warning #58884
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
Closed
Conversation
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
The TypeScript team hasn't accepted the linked issue #58561. If you can get it accepted, this PR will have a better chance of being reviewed. |
jakebailey
reviewed
Jun 17, 2024
6 tasks
jonshea
added a commit
to jonshea/TypeScript
that referenced
this pull request
Aug 22, 2025
This PR continues [Allow leading underscore for types...](microsoft#58884), taking into account feedback from https://github.com/microsoft/TypeScript/pull/58884/files#r1643108204. The initial commit on this PR is original work by @a-tarasyuk. The second commit enhances the test suite and reverts the change to checker.ts to get a new baseline on the test suite for easier comparison with the changes. The third commit changes checker.ts to allow any unused local if it is prefixed with an underscore. This has the effect of newly allowing the following unused declarations: ```ts // Variables were previously allowed only in destructuring and for-loops const _unusedVar = 2; let _unusedLet = 4; var _unusedVar2 = 6; function _unusedFunc() { } const _unusedArrow = () => { }; class _UnusedClass { } interface _UnusedInterface { } type _UnusedType = string; enum _UnusedEnum { A } namespace _UnusedNamespace { ... } ``` As far as I can tell, enum members and properties are not checked in the checkUnusedLocalsAndParameters function, and we do not need to special-case them. Closes microsoft#58561
jonshea
added a commit
to jonshea/TypeScript
that referenced
this pull request
Aug 23, 2025
This PR continues [Allow leading underscore for types...](microsoft#58884), taking into account feedback from https://github.com/microsoft/TypeScript/pull/58884/files#r1643108204. The initial commit on this PR is original work by @a-tarasyuk. The second commit enhances the test suite and reverts the change to checker.ts to get a new baseline on the test suite for easier comparison with the changes. The third commit changes checker.ts to allow any unused local if it is prefixed with an underscore. This has the effect of newly allowing the following unused declarations: ```ts // Variables were previously allowed only in destructuring and for-loops const _unusedVar = 2; let _unusedLet = 4; var _unusedVar2 = 6; // These two no longer raise // error TS6198: All destructured elements are unused const { _a, _b } = { _a: 1, _b: 1 }; function f2({_a, _b}) function _unusedFunc() { } const _unusedArrow = () => { }; class _UnusedClass { } interface _UnusedInterface { } type _UnusedType = string; enum _UnusedEnum { A } namespace _UnusedNamespace { ... } ``` As far as I can tell, enum members and properties are not checked in the checkUnusedLocalsAndParameters function, and we do not need to special-case them. Closes microsoft#58561
jonshea
added a commit
to jonshea/TypeScript
that referenced
this pull request
Aug 23, 2025
This PR continues [Allow leading underscore for types...](microsoft#58884), taking into account feedback from https://github.com/microsoft/TypeScript/pull/58884/files#r1643108204. The initial commit on this PR is original work by @a-tarasyuk. The second commit enhances the test suite and reverts the change to checker.ts to get a new baseline on the test suite for easier comparison with the changes. The third commit changes checker.ts to allow any unused local if it is prefixed with an underscore. This has the effect of newly allowing the following unused declarations: ```ts // Variables were previously allowed only in destructuring and for-loops const _unusedVar = 2; let _unusedLet = 4; var _unusedVar2 = 6; // These two no longer raise // error TS6198: All destructured elements are unused const { _a, _b } = { _a: 1, _b: 1 }; function f2({_a, _b}) function _unusedFunc() { } const _unusedArrow = () => { }; class _UnusedClass { } interface _UnusedInterface { } type _UnusedType = string; enum _UnusedEnum { A } namespace _UnusedNamespace { ... } ``` As far as I can tell, enum members and properties are not checked in the checkUnusedLocalsAndParameters function, and we do not need to special-case them. Closes microsoft#58561
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #58561