Skip to content

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #58561

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jun 16, 2024
@typescript-bot
Copy link
Collaborator

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.

@sandersn sandersn requested a review from iisaduan June 18, 2024 22:31
@a-tarasyuk a-tarasyuk closed this Mar 11, 2025
@github-project-automation github-project-automation bot moved this from Waiting on reviewers to Done in PR Backlog Mar 11, 2025
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
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
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow leading underscore for types to bypass noUnusedLocals warning
4 participants