fix: suppress TS4055/TS4073 for protected methods using typeof parameter#63222
fix: suppress TS4055/TS4073 for protected methods using typeof parameter#63222umeshmore45 wants to merge 3 commits intomicrosoft:mainfrom
Conversation
…sing typeof parameter Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
Fixes an incorrect TS4055/TS4073 accessibility diagnostic during declaration emit when a protected method signature uses a typeof parameterName type query.
Changes:
- Updates
isEntityNameVisibleto treat parameter symbols as always accessible within their containing signature during declaration emit. - Adds a new compiler test case for
protectedmethod return types usingtypeofon a parameter. - Adds new baseline outputs for the new test.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/checker.ts | Short-circuits symbol visibility for parameter symbols to prevent TS4055/TS4073 in declaration emit for typeof paramName. |
| tests/cases/compiler/protectedMethodTypeofParameter.ts | New regression test covering protected method return type with Properties[typeof propertyName]. |
| tests/cases/compiler/protectedMethodTypeofParameter.d.ts | Adds a .d.ts alongside the test case (looks like emitted output); flagged in review as likely unintended. |
| tests/baselines/reference/protectedMethodTypeofParameter.js | Baselines the emit output (JS + .d.ts section) for the new test. |
| tests/baselines/reference/protectedMethodTypeofParameter.types | Baselines type information for the .ts input. |
| tests/baselines/reference/protectedMethodTypeofParameter.symbols | Baselines symbol information for the .ts input. |
| tests/baselines/reference/protectedMethodTypeofParameter.d.types | Baselines type information for the emitted .d.ts. |
| tests/baselines/reference/protectedMethodTypeofParameter.d.symbols | Baselines symbol information for the emitted .d.ts. |
You can also share your feedback on Copilot code review. Take the survey.
Parameters are always in scope within their enclosing function. When `typeof paramName` is used in a return type annotation, the parameter symbol should be considered accessible regardless of method visibility (public, protected, private), just like type parameters are. Previously, `isEntityNameVisible` would fall through to `hasVisibleDeclarations` for parameter symbols, which returned `undefined` (parameters are not module-level exports), causing a false-positive TS4055/TS4073 error for protected methods using `typeof parameter` in their return type. Fixes the case: protected method(): Properties[typeof paramName] -- no longer emits TS4055
2ebfe78 to
c000090
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
…e queries Refined the accessibility check for parameter symbols to only apply when they are part of a TypeQuery. This prevents parameter identifiers used as computed property names in type printing from being incorrectly treated as accessible unique-symbol-like keys.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
Fixes #61591
Problem
Using
typeof parameterNamein the return type of aprotectedmethod incorrectly triggered TS4055. The same pattern on apublicmethod worked fine.Root Cause
During declaration emit,
isEntityNameVisibleresolves the symbol fortypeof propertyNameand callshasVisibleDeclarations. Parameters are not part of any module export scope, soisDeclarationVisiblereturnsfalsefor them, causing aNotAccessibleresult and triggering TS4055.Fix
Added an early return in
isEntityNameVisiblefor parameter symbols, mirroring the existing short-circuit forSymbolFlags.TypeParameter. Parameters are always accessible within their function's scope — visibility modifiers on the method don't change that.Checklist
Backlogmilestonemainhereby runtestspasses locally (46,182 conformance tests)tests/cases/compiler/protectedMethodTypeofParameter.ts