Skip to content

Conversation

@ahejlsberg
Copy link
Member

Fixes #2002.

Copilot AI review requested due to automatic review settings November 2, 2025 19:49
~
!!! error TS2304: Cannot find name 'T'.
~
!!! error TS2304: Cannot find name 'T'.
Copy link
Member Author

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.

Copy link
Contributor

Copilot AI left a 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 parseListIndex to propagate JSTypeAliasDeclaration nodes outward when parsing contexts other than source elements or block statements
  • Added test case typedefHoisting.ts to 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

@ahejlsberg ahejlsberg changed the title Hoist @typedefs types to containing scopes that permit them Hoist @typedefs and @import tags to containing scopes that permit them Nov 3, 2025
@ahejlsberg ahejlsberg changed the title Hoist @typedefs and @import tags to containing scopes that permit them Hoist @typedef and @import tags to containing scopes that permit them Nov 3, 2025
@ahejlsberg ahejlsberg enabled auto-merge November 3, 2025 16:14
@ahejlsberg ahejlsberg added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit 13d3e19 Nov 3, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the fix-2002 branch November 3, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSDoc @typedef not hoisted out of classes or interfaces

3 participants