Repository navigation
Fix unused renaming detection in function types - #64900
Wick Studio (wickstudio) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The localized fix matches existing variable-reference handling, with focused regression coverage and no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes #64705 by preventing type-only references from hiding unused destructured renamings in function types.
Changes:
- Checks variable references when deciding whether to report TS2842.
- Adds regression coverage for generics,
typeof, constructor signatures, and ordinary destructuring.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Distinguishes variable usage from type-only references. |
tsc/testdata/tests/cases/compiler/renamingDestructuredPropertyInFunctionType4.ts |
Adds failing and valid regression cases. |
tsc/testdata/baselines/reference/compiler/renamingDestructuredPropertyInFunctionType4.errors.txt |
Records the five expected TS2842 diagnostics. |
Review effort: Balanced
|
@microsoft-github-policy-service agree |
|
If you're willing, this would be much easier to review if it were two commits, one that adds the test and baselines showing bad behavior, then one commit with the fix and baseline update showing it works. |
ed740a4 to
8c94f49
Compare
Thanks, i've split the changes into two commits as suggested the first adds the regression test with the original baseline, and the second applies the fix and updates the baseline and also all local tests are passing |
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Fixes #64705
Analysis
In generic function types, a type-only reference can incorrectly mark a destructured value binding with the same name as used.
The existing
referenceKinds == 0condition treats any reference as a valid use, suppressing the expected TS2842 diagnostic.Fix
Updated the unused-renaming check to examine
SymbolFlagsVariable, distinguishing value references from type-only references.Added regression tests covering generic type parameters, type-only references,
typeofqueries, nested generics, constructor signatures, and ordinary destructuring.Validation
npx hereby validatepassed.npx hereby testpassed.npx hereby test:allpassed.npx hereby lintpassed.npx hereby check:formatpassed.During the passing
test:allrun, a native filesystem callback emittedpanic: EOF. All API tests passed, and the cause of the trace remains unconfirmed.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
npx hereby validatenpx hereby validate --api(not applicable; no API changes)AI Assistance
I selected the issue, directed the investigation, reviewed the results, and coordinated validation across Windows and Linux. OpenAI Codex assisted with the investigation and generated the checker change and regression tests.