Repository navigation
Keep requested alias type arguments when instantiation leaves union/intersection members unchanged - #65593
Closed
Kaique da Silva (ktfth) wants to merge 2 commits into
Closed
Keep requested alias type arguments when instantiation leaves union/intersection members unchanged#65593Kaique da Silva (ktfth) wants to merge 2 commits into
Kaique da Silva (ktfth) wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the alias type-argument preservation change.
No open issues 🎉
What changed in this PR
Fixes #65570 by preserving requested alias type arguments during union and intersection instantiation, preventing declaration emit from referencing out-of-scope type parameters.
Changes:
- Require matching alias type arguments before reusing an unchanged union or intersection type.
- Add cross-file regression coverage for unused parameters, generic inference, and a used-parameter control.
- Record expected declaration output, types, and symbols, including reduction of
number & {}tonumber.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/declarationEmitUnusedAliasTypeParameter.ts |
Adds declaration-emit regression cases. |
tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.types |
Records expected instantiated types. |
tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.symbols |
Records symbol bindings for the test. |
tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.js |
Records JavaScript and corrected declaration output. |
tsc/internal/checker/checker.go |
Checks alias arguments before reusing an existing type. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
Member
|
If you're willing, this would be much easier to review if it were two commits, one that adds the test and baselines showing bad behavior, then one commit with the fix and baseline update showing it works. |
…eter The baselines record the current behavior: the declaration file prints `Labeled<Label>` instead of `Labeled<"user">`, and its four TS2552 errors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
…ntersection members unchanged
instantiateTypeWorker returned the declared union/intersection type whenever its members were
unchanged and the requested alias had the same symbol. For an alias whose type parameter is
unused (`type Labeled<Label> = { id: number } & { name: string }`), instantiating
`Labeled<"user">` then returned the declared type carrying alias arguments [Label], and
declaration emit printed `Labeled<Label>`, an out-of-scope name.
Also compare the alias type arguments before taking the shortcut.
Fixes microsoft#65570
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7
Kaique da Silva (ktfth)
force-pushed
the
fix-65570-alias-type-arguments
branch
from
November 20, 2026 02:25
70f88b6 to
8aeb67a
Compare
Member
|
Closing in favor of #65594 which has clearer baselines and maybe a second-bug-in-a-trenchcoat fix as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65570
Problem. For an alias whose type parameter is unused, e.g.
type Labeled<Label> = { id: number } & { name: string }, declaration emit printedLabeled<Label>instead ofLabeled<"user">. Consumers of the.d.tsthen fail withTS2552: Cannot find name 'Label'. It reproduces cross-file for intersection and union bodies and fornumber & {}.Cause.
instantiateTypeWithAliasintentionally lets these types through so they can be copied with new alias type arguments. But ininstantiateTypeWorker, the union/intersection branch returned the original type when the members were unchanged and the requested alias had the same symbol. The original type is the declared type, whose alias type arguments are[Label].Change. The shortcut also requires the alias type arguments to be equal (
slices.Equal). Otherwise the type is re-created with the requested alias. Fornumber & {}the intersection now reduces tonumber, as it does same-file.Tests. New
declarationEmitUnusedAliasTypeParameter.tscovers intersection, union, brand, inference through a generic call, and a used second parameter as a control. Without the change, its.d.tshas fourTS2552errors. On currentmain,go test ./internal/checker/ ./internal/testrunner/passes with no other baseline changes, andgofmtandgo vet ./internal/checker/are clean.🤖 Generated with Claude Code
https://claude.ai/code/session_0135Ju6nHX6LevBTiiKb5xG7