Repository navigation
fix(isolatedDeclarations): report TS9007/TS9008 for return entity names - #65120
Timur Vural (timurzvural) wants to merge 2 commits into
Conversation
Ryan Cavanaugh (RyanCavanaugh)
left a comment
There was a problem hiding this comment.
Please wash the AI smell off these code comments
There was a problem hiding this comment.
🟢 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>
70d8f19 to
a7516a9
Compare
|
Removed the explanatory comments from |
PR feedback requested no comments in these two files. Co-authored-by: timurzvural <timurzvural@gmail.com>
|
Removed all comments from |
Fixes #65106
Summary
Under the flag
--isolatedDeclarations, nativetscreported 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:
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 checkedIsTypeQueryNode(node)and it had an unconditional entity-name branch, so value-position identifiers hit TS9039.typeFromSingleReturnExpression— UnliketypeFromVariable/typeFromProperty(and Strada'sfailedresult for bare identifiers), a barePseudoTypeInferredfromreturn x/return this.xwas kept as the return pseudotype, so inference fallback looked at the expression. The update treats bareInferred(noErrorNodes) as a failure and falls through toInferred(fn), relying on the signature of the function fn.Testing plan
go -C ./tsc test -run='TestLocal/isolatedDeclaration' ./internal/testrunnerisolatedDeclarationsReturnEntityNamebaselines show TS9007/TS9008