Repository navigation
Fix declaration emit leaking an alias's unused type parameter (Labeled<Label>)
#65594
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
Open
Ryan Cavanaugh (RyanCavanaugh)
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-declaration-emit-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+441
−4
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
966e597
Initial plan
RyanCavanaugh 4f6d3f2
Add test for alias type arguments when the alias's type parameters ar…
RyanCavanaugh a4f8f68
Compare alias type arguments before reusing an uninstantiated union o…
RyanCavanaugh f5f998f
Don't re-reduce an intersection when only its alias is instantiated
RyanCavanaugh cfca1b9
Accept baselines
RyanCavanaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| //// [tests/cases/compiler/declarationEmitUnusedAliasTypeParameter.ts] //// | ||
|
|
||
| //// [types.ts] | ||
| export type Labeled<Label> = { id: number } & { name: string }; | ||
| export type MaybeLabel<Label> = undefined | "x"; | ||
| export type Branded<Label> = number & {}; | ||
| export type Loose<Label> = string & {}; | ||
| export type Relabeled<Label> = Branded<Label>; | ||
| export type UsesSecond<Label, Value> = { id: number } & { value: Value }; | ||
|
|
||
| //// [main.ts] | ||
| import type { Labeled, MaybeLabel, Branded, Loose, Relabeled, UsesSecond } from "./types"; | ||
|
|
||
| declare function id<T>(value: T): T; | ||
| declare function label<L>(value: L): Labeled<L>; | ||
|
|
||
| declare const item: Labeled<"user">; | ||
| declare const maybe: MaybeLabel<"user">; | ||
| declare const branded: Branded<"user">; | ||
| declare const names: "alice" | "bob" | Loose<"user">; | ||
| declare const relabeled: Relabeled<"user">; | ||
| declare const partly: UsesSecond<"user", 1>; | ||
|
|
||
| export const copy = item; | ||
| export const inferred = id(item); | ||
| export const fromCall = label<"admin">("admin"); | ||
| export const maybeCopy = maybe; | ||
| export const brandedCopy = branded; | ||
| export const namesCopy = names; | ||
| export const relabeledCopy = relabeled; | ||
| export const partlyCopy = partly; | ||
|
|
||
| //// [local.ts] | ||
| type LocalLabeled<Label> = { id: number } & { name: string }; | ||
| type LocalBranded<Label> = number & {}; | ||
| type LocalLoose<Label> = string & {}; | ||
|
|
||
| declare const localItem: LocalLabeled<"user">; | ||
| declare const localBranded: LocalBranded<"user">; | ||
| declare const localNames: "alice" | "bob" | LocalLoose<"user">; | ||
|
|
||
| export const localItemCopy = localItem; | ||
| export const localBrandedCopy = localBranded; | ||
| export const localNamesCopy = localNames; | ||
|
|
||
|
|
||
| //// [types.js] | ||
| export {}; | ||
| //// [main.js] | ||
| export const copy = item; | ||
| export const inferred = id(item); | ||
| export const fromCall = label("admin"); | ||
| export const maybeCopy = maybe; | ||
| export const brandedCopy = branded; | ||
| export const namesCopy = names; | ||
| export const relabeledCopy = relabeled; | ||
| export const partlyCopy = partly; | ||
| //// [local.js] | ||
| export const localItemCopy = localItem; | ||
| export const localBrandedCopy = localBranded; | ||
| export const localNamesCopy = localNames; | ||
|
|
||
|
|
||
| //// [types.d.ts] | ||
| export type Labeled<Label> = { | ||
| id: number; | ||
| } & { | ||
| name: string; | ||
| }; | ||
| export type MaybeLabel<Label> = undefined | "x"; | ||
| export type Branded<Label> = number & {}; | ||
| export type Loose<Label> = string & {}; | ||
| export type Relabeled<Label> = Branded<Label>; | ||
| export type UsesSecond<Label, Value> = { | ||
| id: number; | ||
| } & { | ||
| value: Value; | ||
| }; | ||
| //// [main.d.ts] | ||
| import type { Labeled, MaybeLabel, Branded, Loose, Relabeled, UsesSecond } from "./types"; | ||
| export declare const copy: Labeled<"user">; | ||
| export declare const inferred: Labeled<"user">; | ||
| export declare const fromCall: Labeled<"admin">; | ||
| export declare const maybeCopy: MaybeLabel<"user">; | ||
| export declare const brandedCopy: Branded<"user">; | ||
| export declare const namesCopy: "alice" | "bob" | Loose<"user">; | ||
| export declare const relabeledCopy: Relabeled<"user">; | ||
| export declare const partlyCopy: UsesSecond<"user", 1>; | ||
| //// [local.d.ts] | ||
| type LocalLabeled<Label> = { | ||
| id: number; | ||
| } & { | ||
| name: string; | ||
| }; | ||
| type LocalBranded<Label> = number & {}; | ||
| type LocalLoose<Label> = string & {}; | ||
| export declare const localItemCopy: LocalLabeled<"user">; | ||
| export declare const localBrandedCopy: LocalBranded<"user">; | ||
| export declare const localNamesCopy: "alice" | "bob" | LocalLoose<"user">; | ||
| export {}; |
155 changes: 155 additions & 0 deletions
155
tsc/testdata/baselines/reference/compiler/declarationEmitUnusedAliasTypeParameter.symbols
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| //// [tests/cases/compiler/declarationEmitUnusedAliasTypeParameter.ts] //// | ||
|
|
||
| === types.ts === | ||
| export type Labeled<Label> = { id: number } & { name: string }; | ||
| >Labeled : Symbol(Labeled, Decl(types.ts, 0, 0)) | ||
| >Label : Symbol(Label, Decl(types.ts, 0, 20)) | ||
| >id : Symbol(id, Decl(types.ts, 0, 30)) | ||
| >name : Symbol(name, Decl(types.ts, 0, 47)) | ||
|
|
||
| export type MaybeLabel<Label> = undefined | "x"; | ||
| >MaybeLabel : Symbol(MaybeLabel, Decl(types.ts, 0, 63)) | ||
| >Label : Symbol(Label, Decl(types.ts, 1, 23)) | ||
|
|
||
| export type Branded<Label> = number & {}; | ||
| >Branded : Symbol(Branded, Decl(types.ts, 1, 48)) | ||
| >Label : Symbol(Label, Decl(types.ts, 2, 20)) | ||
|
|
||
| export type Loose<Label> = string & {}; | ||
| >Loose : Symbol(Loose, Decl(types.ts, 2, 41)) | ||
| >Label : Symbol(Label, Decl(types.ts, 3, 18)) | ||
|
|
||
| export type Relabeled<Label> = Branded<Label>; | ||
| >Relabeled : Symbol(Relabeled, Decl(types.ts, 3, 39)) | ||
| >Label : Symbol(Label, Decl(types.ts, 4, 22)) | ||
| >Branded : Symbol(Branded, Decl(types.ts, 1, 48)) | ||
| >Label : Symbol(Label, Decl(types.ts, 4, 22)) | ||
|
|
||
| export type UsesSecond<Label, Value> = { id: number } & { value: Value }; | ||
| >UsesSecond : Symbol(UsesSecond, Decl(types.ts, 4, 46)) | ||
| >Label : Symbol(Label, Decl(types.ts, 5, 23)) | ||
| >Value : Symbol(Value, Decl(types.ts, 5, 29)) | ||
| >id : Symbol(id, Decl(types.ts, 5, 40)) | ||
| >value : Symbol(value, Decl(types.ts, 5, 57)) | ||
| >Value : Symbol(Value, Decl(types.ts, 5, 29)) | ||
|
|
||
| === main.ts === | ||
| import type { Labeled, MaybeLabel, Branded, Loose, Relabeled, UsesSecond } from "./types"; | ||
| >Labeled : Symbol(Labeled, Decl(main.ts, 0, 13)) | ||
| >MaybeLabel : Symbol(MaybeLabel, Decl(main.ts, 0, 22)) | ||
| >Branded : Symbol(Branded, Decl(main.ts, 0, 34)) | ||
| >Loose : Symbol(Loose, Decl(main.ts, 0, 43)) | ||
| >Relabeled : Symbol(Relabeled, Decl(main.ts, 0, 50)) | ||
| >UsesSecond : Symbol(UsesSecond, Decl(main.ts, 0, 61)) | ||
|
|
||
| declare function id<T>(value: T): T; | ||
| >id : Symbol(id, Decl(main.ts, 0, 90)) | ||
| >T : Symbol(T, Decl(main.ts, 2, 20)) | ||
| >value : Symbol(value, Decl(main.ts, 2, 23)) | ||
| >T : Symbol(T, Decl(main.ts, 2, 20)) | ||
| >T : Symbol(T, Decl(main.ts, 2, 20)) | ||
|
|
||
| declare function label<L>(value: L): Labeled<L>; | ||
| >label : Symbol(label, Decl(main.ts, 2, 36)) | ||
| >L : Symbol(L, Decl(main.ts, 3, 23)) | ||
| >value : Symbol(value, Decl(main.ts, 3, 26)) | ||
| >L : Symbol(L, Decl(main.ts, 3, 23)) | ||
| >Labeled : Symbol(Labeled, Decl(main.ts, 0, 13)) | ||
| >L : Symbol(L, Decl(main.ts, 3, 23)) | ||
|
|
||
| declare const item: Labeled<"user">; | ||
| >item : Symbol(item, Decl(main.ts, 5, 13)) | ||
| >Labeled : Symbol(Labeled, Decl(main.ts, 0, 13)) | ||
|
|
||
| declare const maybe: MaybeLabel<"user">; | ||
| >maybe : Symbol(maybe, Decl(main.ts, 6, 13)) | ||
| >MaybeLabel : Symbol(MaybeLabel, Decl(main.ts, 0, 22)) | ||
|
|
||
| declare const branded: Branded<"user">; | ||
| >branded : Symbol(branded, Decl(main.ts, 7, 13)) | ||
| >Branded : Symbol(Branded, Decl(main.ts, 0, 34)) | ||
|
|
||
| declare const names: "alice" | "bob" | Loose<"user">; | ||
| >names : Symbol(names, Decl(main.ts, 8, 13)) | ||
| >Loose : Symbol(Loose, Decl(main.ts, 0, 43)) | ||
|
|
||
| declare const relabeled: Relabeled<"user">; | ||
| >relabeled : Symbol(relabeled, Decl(main.ts, 9, 13)) | ||
| >Relabeled : Symbol(Relabeled, Decl(main.ts, 0, 50)) | ||
|
|
||
| declare const partly: UsesSecond<"user", 1>; | ||
| >partly : Symbol(partly, Decl(main.ts, 10, 13)) | ||
| >UsesSecond : Symbol(UsesSecond, Decl(main.ts, 0, 61)) | ||
|
|
||
| export const copy = item; | ||
| >copy : Symbol(copy, Decl(main.ts, 12, 12)) | ||
| >item : Symbol(item, Decl(main.ts, 5, 13)) | ||
|
|
||
| export const inferred = id(item); | ||
| >inferred : Symbol(inferred, Decl(main.ts, 13, 12)) | ||
| >id : Symbol(id, Decl(main.ts, 0, 90)) | ||
| >item : Symbol(item, Decl(main.ts, 5, 13)) | ||
|
|
||
| export const fromCall = label<"admin">("admin"); | ||
| >fromCall : Symbol(fromCall, Decl(main.ts, 14, 12)) | ||
| >label : Symbol(label, Decl(main.ts, 2, 36)) | ||
|
|
||
| export const maybeCopy = maybe; | ||
| >maybeCopy : Symbol(maybeCopy, Decl(main.ts, 15, 12)) | ||
| >maybe : Symbol(maybe, Decl(main.ts, 6, 13)) | ||
|
|
||
| export const brandedCopy = branded; | ||
| >brandedCopy : Symbol(brandedCopy, Decl(main.ts, 16, 12)) | ||
| >branded : Symbol(branded, Decl(main.ts, 7, 13)) | ||
|
|
||
| export const namesCopy = names; | ||
| >namesCopy : Symbol(namesCopy, Decl(main.ts, 17, 12)) | ||
| >names : Symbol(names, Decl(main.ts, 8, 13)) | ||
|
|
||
| export const relabeledCopy = relabeled; | ||
| >relabeledCopy : Symbol(relabeledCopy, Decl(main.ts, 18, 12)) | ||
| >relabeled : Symbol(relabeled, Decl(main.ts, 9, 13)) | ||
|
|
||
| export const partlyCopy = partly; | ||
| >partlyCopy : Symbol(partlyCopy, Decl(main.ts, 19, 12)) | ||
| >partly : Symbol(partly, Decl(main.ts, 10, 13)) | ||
|
|
||
| === local.ts === | ||
| type LocalLabeled<Label> = { id: number } & { name: string }; | ||
| >LocalLabeled : Symbol(LocalLabeled, Decl(local.ts, 0, 0)) | ||
| >Label : Symbol(Label, Decl(local.ts, 0, 18)) | ||
| >id : Symbol(id, Decl(local.ts, 0, 28)) | ||
| >name : Symbol(name, Decl(local.ts, 0, 45)) | ||
|
|
||
| type LocalBranded<Label> = number & {}; | ||
| >LocalBranded : Symbol(LocalBranded, Decl(local.ts, 0, 61)) | ||
| >Label : Symbol(Label, Decl(local.ts, 1, 18)) | ||
|
|
||
| type LocalLoose<Label> = string & {}; | ||
| >LocalLoose : Symbol(LocalLoose, Decl(local.ts, 1, 39)) | ||
| >Label : Symbol(Label, Decl(local.ts, 2, 16)) | ||
|
|
||
| declare const localItem: LocalLabeled<"user">; | ||
| >localItem : Symbol(localItem, Decl(local.ts, 4, 13)) | ||
| >LocalLabeled : Symbol(LocalLabeled, Decl(local.ts, 0, 0)) | ||
|
|
||
| declare const localBranded: LocalBranded<"user">; | ||
| >localBranded : Symbol(localBranded, Decl(local.ts, 5, 13)) | ||
| >LocalBranded : Symbol(LocalBranded, Decl(local.ts, 0, 61)) | ||
|
|
||
| declare const localNames: "alice" | "bob" | LocalLoose<"user">; | ||
| >localNames : Symbol(localNames, Decl(local.ts, 6, 13)) | ||
| >LocalLoose : Symbol(LocalLoose, Decl(local.ts, 1, 39)) | ||
|
|
||
| export const localItemCopy = localItem; | ||
| >localItemCopy : Symbol(localItemCopy, Decl(local.ts, 8, 12)) | ||
| >localItem : Symbol(localItem, Decl(local.ts, 4, 13)) | ||
|
|
||
| export const localBrandedCopy = localBranded; | ||
| >localBrandedCopy : Symbol(localBrandedCopy, Decl(local.ts, 9, 12)) | ||
| >localBranded : Symbol(localBranded, Decl(local.ts, 5, 13)) | ||
|
|
||
| export const localNamesCopy = localNames; | ||
| >localNamesCopy : Symbol(localNamesCopy, Decl(local.ts, 10, 12)) | ||
| >localNames : Symbol(localNames, Decl(local.ts, 6, 13)) | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Given this, I assume when we take Wesley's changes to drop this construct, none of this will matter?