mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 20:25:23 -06:00
Merge pull request #19697 from Microsoft/fixFreshLiteralsInIntersections
Fix fresh literals in intersections
This commit is contained in:
commit
a8d3cd6dfe
@ -7592,11 +7592,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
@ -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))
|
||||
|
||||
@ -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
tests/cases/compiler/freshLiteralTypesInIntersections.ts
Normal file
7
tests/cases/compiler/freshLiteralTypesInIntersections.ts
Normal file
@ -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");
|
||||
Loading…
x
Reference in New Issue
Block a user