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

Regression in detecting unused parameters in 5.5.0-beta #58493

Open
danvk opened this issue May 10, 2024 · 1 comment Β· May be fixed by #58514
Open

Regression in detecting unused parameters in 5.5.0-beta #58493

danvk opened this issue May 10, 2024 · 1 comment Β· May be fixed by #58514
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@danvk
Copy link
Contributor

danvk commented May 10, 2024

πŸ”Ž Search Terms

  • 5.5 predicate
  • 6133

πŸ•— Version & Regression Information

  • This changed between versions 5.4.5 and 5.5.0-beta

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-beta#code/GYVwdgxgLglg9mABABwE4FMAmB1GUAWAqmCAM5YAUAhgFyLgDWYcA7mAJSIDeAUIv4gxQQqJAEIxAWSoEAdKiphMcALYV2Abh4BfHkA

πŸ’» Code

function predWithUnused(a: unknown) {
    return !!Math.random();
}

πŸ™ Actual behavior

TS 5.5.0-beta reports that a is used.

πŸ™‚ Expected behavior

It should be reported as unused.

Additional information about the issue

Compare 5.4.5

image

vs. 5.5.0-beta:

image

This was almost certainly broken by #57465. It adds a call to getTypeOfSymbol for every parameter of a candidate predicate function in checkIfExpressionRefinesAnyParameter. This marks each of those parameters as referenced, even though there's no reason to assume that they are, since this call is speculative.

This also affects the "Delete all unused declarations" quickfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@danvk @sandersn @RyanCavanaugh @typescript-bot and others