Skip to content

Regression in detecting unused parameters in 5.5.0-betaΒ #58493

Closed
@danvk

Description

@danvk

πŸ”Ž 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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions