Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7589,11 +7589,11 @@ namespace ts {
}
}

// Add the given types to the given type set. Order is preserved, duplicates are removed,
// and nested types of the given kind are flattened into the set.
// Add the given types to the given type set. Order is preserved, freshness is removed from literal
// types, duplicates are removed, and nested types of the given kind are flattened into the set.
function addTypesToIntersection(typeSet: TypeSet, types: Type[]) {
for (const type of types) {
addTypeToIntersection(typeSet, type);
addTypeToIntersection(typeSet, getRegularTypeOfLiteralType(type));
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/freshLiteralTypesInIntersections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [freshLiteralTypesInIntersections.ts]
// Repro from #19657

declare function func<A extends string, B extends A>(a: A, b: B[]): (ab: A & B) => void;
const q = func("x" as "x" | "y", ["x"]);
q("x");


//// [freshLiteralTypesInIntersections.js]
"use strict";
// Repro from #19657
var q = func("x", ["x"]);
q("x");
23 changes: 23 additions & 0 deletions tests/baselines/reference/freshLiteralTypesInIntersections.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/compiler/freshLiteralTypesInIntersections.ts ===
// Repro from #19657

declare function func<A extends string, B extends A>(a: A, b: B[]): (ab: A & B) => void;
>func : Symbol(func, Decl(freshLiteralTypesInIntersections.ts, 0, 0))
>A : Symbol(A, Decl(freshLiteralTypesInIntersections.ts, 2, 22))
>B : Symbol(B, Decl(freshLiteralTypesInIntersections.ts, 2, 39))
>A : Symbol(A, Decl(freshLiteralTypesInIntersections.ts, 2, 22))
>a : Symbol(a, Decl(freshLiteralTypesInIntersections.ts, 2, 53))
>A : Symbol(A, Decl(freshLiteralTypesInIntersections.ts, 2, 22))
>b : Symbol(b, Decl(freshLiteralTypesInIntersections.ts, 2, 58))
>B : Symbol(B, Decl(freshLiteralTypesInIntersections.ts, 2, 39))
>ab : Symbol(ab, Decl(freshLiteralTypesInIntersections.ts, 2, 69))
>A : Symbol(A, Decl(freshLiteralTypesInIntersections.ts, 2, 22))
>B : Symbol(B, Decl(freshLiteralTypesInIntersections.ts, 2, 39))

const q = func("x" as "x" | "y", ["x"]);
>q : Symbol(q, Decl(freshLiteralTypesInIntersections.ts, 3, 5))
>func : Symbol(func, Decl(freshLiteralTypesInIntersections.ts, 0, 0))

q("x");
>q : Symbol(q, Decl(freshLiteralTypesInIntersections.ts, 3, 5))

30 changes: 30 additions & 0 deletions tests/baselines/reference/freshLiteralTypesInIntersections.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/freshLiteralTypesInIntersections.ts ===
// Repro from #19657

declare function func<A extends string, B extends A>(a: A, b: B[]): (ab: A & B) => void;
>func : <A extends string, B extends A>(a: A, b: B[]) => (ab: A & B) => void
>A : A
>B : B
>A : A
>a : A
>A : A
>b : B[]
>B : B
>ab : A & B
>A : A
>B : B

const q = func("x" as "x" | "y", ["x"]);
>q : (ab: "x") => void
>func("x" as "x" | "y", ["x"]) : (ab: "x") => void
>func : <A extends string, B extends A>(a: A, b: B[]) => (ab: A & B) => void
>"x" as "x" | "y" : "x" | "y"
>"x" : "x"
>["x"] : "x"[]
>"x" : "x"

q("x");
>q("x") : void
>q : (ab: "x") => void
>"x" : "x"

7 changes: 7 additions & 0 deletions tests/cases/compiler/freshLiteralTypesInIntersections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @strict: true

// Repro from #19657

declare function func<A extends string, B extends A>(a: A, b: B[]): (ab: A & B) => void;
const q = func("x" as "x" | "y", ["x"]);
q("x");