Skip to content

fix(isolatedDeclarations): report TS9007/TS9008 for return entity names - #65120

Open
Timur Vural (timurzvural) wants to merge 2 commits into
microsoft:mainfrom
timurzvural:cursor/fix-65106
Open

Timur Vural (timurzvural) wants to merge 2 commits into
microsoft:mainfrom
timurzvural:cursor/fix-65106

Conversation

@timurzvural

@timurzvural Timur Vural (timurzvural) commented Nov 2, 2026 •

Copy link
Copy Markdown

Fixes #65106

Summary

Under the flag --isolatedDeclarations, native tsc reported the wrong diagnostics when a function return expression involved the return of an entity name:

For "return x", TS9039 private name was the actual error, vs. the expected "TS9007 add return type".
For "return this.x", TS9013 expression was the actual error, vs. the expected TS9008 add return type.

There were two related port mistakes:

  1. diagnostics.go — The entity-in-type-node error is the diagnostic for an entity name used inside a type when that name isn’t safely usable for declaration emit. Strada only emits the entity-in-type-node error when (isPartOfTypeNode(node) \|\| isTypeQueryNode(node.parent)) && (isEntityName(node) \|\| isEntityNameExpression(node)). Go checked IsTypeQueryNode(node) and it had an unconditional entity-name branch, so value-position identifiers hit TS9039.

  2. typeFromSingleReturnExpression — Unlike typeFromVariable / typeFromProperty (and Strada's failed result for bare identifiers), a bare PseudoTypeInferred from return x / return this.x was kept as the return pseudotype, so inference fallback looked at the expression. The update treats bare Inferred (no ErrorNodes) as a failure and falls through to Inferred(fn), relying on the signature of the function fn.

Testing plan

  • go -C ./tsc test -run='TestLocal/isolatedDeclaration' ./internal/testrunner
  • New isolatedDeclarationsReturnEntityName baselines show TS9007/TS9008
  • Verified against issue reproduction: native diagnostics now match classic 6.0.3

Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:54
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 2, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 2, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wash the AI smell off these code comments

@github-project-automation github-project-automation Bot moved this from Not started to Waiting on author in PR Backlog Nov 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the changes aligning isolated-declaration return diagnostics with classic TypeScript.

No open issues 🎉

What changed in this PR

Fixes #65106 by aligning native TypeScript’s --isolatedDeclarations diagnostics with classic TypeScript for return x and return this.x, reporting missing return-type annotations instead of private-name or expression errors.

Changes:

  • Restricts private-name diagnostics to entity names in type positions.
  • Falls back to signature-level diagnostics when return-expression inference fails without specific error nodes.
  • Adds regression coverage and baselines for TS9007 and TS9008.
File Description
tsc/​testdata/​tests/​cases/​compiler/​isolatedDeclarationsReturnEntityName.ts Adds function and method return regression cases.
tsc/​testdata/​baselines/​reference/​compiler/​isolatedDeclarationsReturnEntityName.types Records expected inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​isolatedDeclarationsReturnEntityName.symbols Records expected symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​isolatedDeclarationsReturnEntityName.js Records expected JavaScript output.
tsc/​testdata/​baselines/​reference/​compiler/​isolatedDeclarationsReturnEntityName.errors.txt Records TS9007/TS9008 and return-annotation guidance.
tsc/​internal/​transformers/​declarations/​diagnostics.go Corrects type-position and parent type-query checks.
tsc/​internal/​pseudochecker/​lookup.go Routes unsupported return inference to signature-level diagnostics.

Review effort: Balanced

Restore Strada's combined condition for createEntityInTypeNodeError so
value-position identifiers are not misclassified as private-in-type-node
(TS9039). Also align typeFromSingleReturnExpression with typeFromVariable:
a bare PseudoTypeInferred from return expressions (Identifier, this.x)
is treated as failure so inference fallback reports on the signature
(TS9007/TS9008) instead of the expression (TS9013).

Fixes #65106

Co-authored-by: timurzvural <timurzvural@gmail.com>
@timurzvural

Copy link
Copy Markdown
Author

Removed the explanatory comments from lookup.go and diagnostics.go — the logic-only changes remain.

PR feedback requested no comments in these two files.

Co-authored-by: timurzvural <timurzvural@gmail.com>
@timurzvural

Copy link
Copy Markdown
Author

Removed all comments from tsc/internal/pseudochecker/lookup.go and tsc/internal/transformers/declarations/diagnostics.go (40480ab).

This branch has not been deployed

No deployments
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

Status: Waiting on author

Development

Successfully merging this pull request may close these issues.

4 participants