-
Notifications
You must be signed in to change notification settings - Fork 730
Hoist @typedef and @import tags to containing scopes that permit them #2003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| ~ | ||
| !!! error TS2304: Cannot find name 'T'. | ||
| ~ | ||
| !!! error TS2304: Cannot find name 'T'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These errors are not reported by the old compiler, yet it still hoists and generates an invalid .d.ts file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements hoisting of @typedef declarations from class member contexts to the module scope, allowing them to be referenced outside of their declaration context. The key change enables JSDoc @typedef and @callback tags defined within class members to be visible at the module level.
Key Changes
- Modified
parseListIndexto propagateJSTypeAliasDeclarationnodes outward when parsing contexts other than source elements or block statements - Added test case
typedefHoisting.tsto verify the hoisting behavior - Updated baselines showing improved type resolution and elimination of "Cannot find name" errors
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| testdata/tests/cases/compiler/typedefHoisting.ts | New test case demonstrating typedef hoisting from class members |
| internal/parser/parser.go | Core parser logic to propagate JSTypeAliasDeclaration nodes to outer scope |
| testdata/baselines/reference/compiler/typedefHoisting.* | New baseline files for the typedef hoisting test |
| testdata/baselines/reference/submodule/conformance/callbackOnConstructor.* | Updated baselines showing eliminated error and corrected type exports |
| testdata/baselines/reference/submodule/conformance/typedefOnSemicolonClassElement.* | Updated baselines showing correct typedef hoisting to module scope |
| testdata/baselines/reference/submodule/conformance/jsdocTemplateClass.* | Updated baselines with new errors for typedefs referencing class type parameters |
| testdata/baselines/reference/submodule/conformance/typedefInnerNamepaths.* | Updated baselines with additional duplicate identifier errors |
Fixes #2002.