Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23034,7 +23034,7 @@ func (c *Checker) instantiateTypeWorker(t *Type, m *TypeMapper, alias *TypeAlias
}
types := source.Types()
newTypes := c.instantiateTypes(types, m)
if core.Same(newTypes, types) && alias.Symbol() == t.alias.Symbol() {
if core.Same(newTypes, types) && alias.Symbol() == t.alias.Symbol() && slices.Equal(alias.TypeArguments(), t.alias.TypeArguments()) {
return t
}
if alias == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//// [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 UsesSecond<Label, Value> = { id: number } & { value: Value };

//// [main.ts]
import type { Labeled, MaybeLabel, Branded, UsesSecond } from "./types";

declare function id<T>(value: T): T;
declare const item: Labeled<"user">;
declare const maybe: MaybeLabel<"user">;
declare const branded: Branded<"user">;
declare const partly: UsesSecond<"user", 1>;

export const copy = item;
export const inferred = id(item);
export const maybeCopy = maybe;
export const brandedCopy = branded;
export const partlyCopy = partly;


//// [types.js]
export {};
//// [main.js]
export const copy = item;
export const inferred = id(item);
export const maybeCopy = maybe;
export const brandedCopy = branded;
export const partlyCopy = partly;


//// [types.d.ts]
export type Labeled<Label> = {
id: number;
} & {
name: string;
};
export type MaybeLabel<Label> = undefined | "x";
export type Branded<Label> = number & {};
export type UsesSecond<Label, Value> = {
id: number;
} & {
value: Value;
};
//// [main.d.ts]
import type { Labeled, MaybeLabel, UsesSecond } from "./types";
export declare const copy: Labeled<"user">;
export declare const inferred: Labeled<"user">;
export declare const maybeCopy: MaybeLabel<"user">;
export declare const brandedCopy: number;
export declare const partlyCopy: UsesSecond<"user", 1>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//// [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 UsesSecond<Label, Value> = { id: number } & { value: Value };
>UsesSecond : Symbol(UsesSecond, Decl(types.ts, 2, 41))
>Label : Symbol(Label, Decl(types.ts, 3, 23))
>Value : Symbol(Value, Decl(types.ts, 3, 29))
>id : Symbol(id, Decl(types.ts, 3, 40))
>value : Symbol(value, Decl(types.ts, 3, 57))
>Value : Symbol(Value, Decl(types.ts, 3, 29))

=== main.ts ===
import type { Labeled, MaybeLabel, Branded, 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))
>UsesSecond : Symbol(UsesSecond, Decl(main.ts, 0, 43))

declare function id<T>(value: T): T;
>id : Symbol(id, Decl(main.ts, 0, 72))
>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 const item: Labeled<"user">;
>item : Symbol(item, Decl(main.ts, 3, 13))
>Labeled : Symbol(Labeled, Decl(main.ts, 0, 13))

declare const maybe: MaybeLabel<"user">;
>maybe : Symbol(maybe, Decl(main.ts, 4, 13))
>MaybeLabel : Symbol(MaybeLabel, Decl(main.ts, 0, 22))

declare const branded: Branded<"user">;
>branded : Symbol(branded, Decl(main.ts, 5, 13))
>Branded : Symbol(Branded, Decl(main.ts, 0, 34))

declare const partly: UsesSecond<"user", 1>;
>partly : Symbol(partly, Decl(main.ts, 6, 13))
>UsesSecond : Symbol(UsesSecond, Decl(main.ts, 0, 43))

export const copy = item;
>copy : Symbol(copy, Decl(main.ts, 8, 12))
>item : Symbol(item, Decl(main.ts, 3, 13))

export const inferred = id(item);
>inferred : Symbol(inferred, Decl(main.ts, 9, 12))
>id : Symbol(id, Decl(main.ts, 0, 72))
>item : Symbol(item, Decl(main.ts, 3, 13))

export const maybeCopy = maybe;
>maybeCopy : Symbol(maybeCopy, Decl(main.ts, 10, 12))
>maybe : Symbol(maybe, Decl(main.ts, 4, 13))

export const brandedCopy = branded;
>brandedCopy : Symbol(brandedCopy, Decl(main.ts, 11, 12))
>branded : Symbol(branded, Decl(main.ts, 5, 13))

export const partlyCopy = partly;
>partlyCopy : Symbol(partlyCopy, Decl(main.ts, 12, 12))
>partly : Symbol(partly, Decl(main.ts, 6, 13))

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//// [tests/cases/compiler/declarationEmitUnusedAliasTypeParameter.ts] ////

=== types.ts ===
export type Labeled<Label> = { id: number } & { name: string };
>Labeled : Labeled<Label>
>id : number
>name : string

export type MaybeLabel<Label> = undefined | "x";
>MaybeLabel : MaybeLabel<Label>

export type Branded<Label> = number & {};
>Branded : Branded<Label>

export type UsesSecond<Label, Value> = { id: number } & { value: Value };
>UsesSecond : UsesSecond<Label, Value>
>id : number
>value : Value

=== main.ts ===
import type { Labeled, MaybeLabel, Branded, UsesSecond } from "./types";
>Labeled : Labeled<Label>
>MaybeLabel : MaybeLabel<Label>
>Branded : Branded<Label>
>UsesSecond : UsesSecond<Label, Value>

declare function id<T>(value: T): T;
>id : <T>(value: T) => T
>value : T

declare const item: Labeled<"user">;
>item : Labeled<"user">

declare const maybe: MaybeLabel<"user">;
>maybe : MaybeLabel<"user">

declare const branded: Branded<"user">;
>branded : number

declare const partly: UsesSecond<"user", 1>;
>partly : UsesSecond<"user", 1>

export const copy = item;
>copy : Labeled<"user">
>item : Labeled<"user">

export const inferred = id(item);
>inferred : Labeled<"user">
>id(item) : Labeled<"user">
>id : <T>(value: T) => T
>item : Labeled<"user">

export const maybeCopy = maybe;
>maybeCopy : MaybeLabel<"user">
>maybe : MaybeLabel<"user">

export const brandedCopy = branded;
>brandedCopy : number
>branded : number

export const partlyCopy = partly;
>partlyCopy : UsesSecond<"user", 1>
>partly : UsesSecond<"user", 1>

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @declaration: true
// @strict: true

// @filename: types.ts
export type Labeled<Label> = { id: number } & { name: string };
export type MaybeLabel<Label> = undefined | "x";
export type Branded<Label> = number & {};
export type UsesSecond<Label, Value> = { id: number } & { value: Value };

// @filename: main.ts
import type { Labeled, MaybeLabel, Branded, UsesSecond } from "./types";

declare function id<T>(value: T): T;
declare const item: Labeled<"user">;
declare const maybe: MaybeLabel<"user">;
declare const branded: Branded<"user">;
declare const partly: UsesSecond<"user", 1>;

export const copy = item;
export const inferred = id(item);
export const maybeCopy = maybe;
export const brandedCopy = branded;
export const partlyCopy = partly;