diff --git a/tests/baselines/reference/intersectionTypeInference2.js b/tests/baselines/reference/intersectionTypeInference2.js new file mode 100644 index 00000000000..804b8d85206 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference2.js @@ -0,0 +1,23 @@ +//// [intersectionTypeInference2.ts] +declare function f(x: { prop: T }): T; + +declare const a: { prop: string } & { prop: number }; +declare const b: { prop: string & number }; + +f(a); // string & number +f(b); // string & number + +// Repro from #18354 + +declare function f2(obj: {[K in keyof T]: T[K]}, key: Key): T[Key]; + +declare const obj: { a: string } & { b: string }; +f2(obj, 'a'); +f2(obj, 'b'); + + +//// [intersectionTypeInference2.js] +f(a); // string & number +f(b); // string & number +f2(obj, 'a'); +f2(obj, 'b'); diff --git a/tests/baselines/reference/intersectionTypeInference2.symbols b/tests/baselines/reference/intersectionTypeInference2.symbols new file mode 100644 index 00000000000..b04de204de1 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference2.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/types/intersection/intersectionTypeInference2.ts === +declare function f(x: { prop: T }): T; +>f : Symbol(f, Decl(intersectionTypeInference2.ts, 0, 0)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 0, 19)) +>x : Symbol(x, Decl(intersectionTypeInference2.ts, 0, 22)) +>prop : Symbol(prop, Decl(intersectionTypeInference2.ts, 0, 26)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 0, 19)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 0, 19)) + +declare const a: { prop: string } & { prop: number }; +>a : Symbol(a, Decl(intersectionTypeInference2.ts, 2, 13)) +>prop : Symbol(prop, Decl(intersectionTypeInference2.ts, 2, 18)) +>prop : Symbol(prop, Decl(intersectionTypeInference2.ts, 2, 37)) + +declare const b: { prop: string & number }; +>b : Symbol(b, Decl(intersectionTypeInference2.ts, 3, 13)) +>prop : Symbol(prop, Decl(intersectionTypeInference2.ts, 3, 18)) + +f(a); // string & number +>f : Symbol(f, Decl(intersectionTypeInference2.ts, 0, 0)) +>a : Symbol(a, Decl(intersectionTypeInference2.ts, 2, 13)) + +f(b); // string & number +>f : Symbol(f, Decl(intersectionTypeInference2.ts, 0, 0)) +>b : Symbol(b, Decl(intersectionTypeInference2.ts, 3, 13)) + +// Repro from #18354 + +declare function f2(obj: {[K in keyof T]: T[K]}, key: Key): T[Key]; +>f2 : Symbol(f2, Decl(intersectionTypeInference2.ts, 6, 5)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 10, 20)) +>Key : Symbol(Key, Decl(intersectionTypeInference2.ts, 10, 22)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 10, 20)) +>obj : Symbol(obj, Decl(intersectionTypeInference2.ts, 10, 44)) +>K : Symbol(K, Decl(intersectionTypeInference2.ts, 10, 51)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 10, 20)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 10, 20)) +>K : Symbol(K, Decl(intersectionTypeInference2.ts, 10, 51)) +>key : Symbol(key, Decl(intersectionTypeInference2.ts, 10, 72)) +>Key : Symbol(Key, Decl(intersectionTypeInference2.ts, 10, 22)) +>T : Symbol(T, Decl(intersectionTypeInference2.ts, 10, 20)) +>Key : Symbol(Key, Decl(intersectionTypeInference2.ts, 10, 22)) + +declare const obj: { a: string } & { b: string }; +>obj : Symbol(obj, Decl(intersectionTypeInference2.ts, 12, 13)) +>a : Symbol(a, Decl(intersectionTypeInference2.ts, 12, 20)) +>b : Symbol(b, Decl(intersectionTypeInference2.ts, 12, 36)) + +f2(obj, 'a'); +>f2 : Symbol(f2, Decl(intersectionTypeInference2.ts, 6, 5)) +>obj : Symbol(obj, Decl(intersectionTypeInference2.ts, 12, 13)) + +f2(obj, 'b'); +>f2 : Symbol(f2, Decl(intersectionTypeInference2.ts, 6, 5)) +>obj : Symbol(obj, Decl(intersectionTypeInference2.ts, 12, 13)) + diff --git a/tests/baselines/reference/intersectionTypeInference2.types b/tests/baselines/reference/intersectionTypeInference2.types new file mode 100644 index 00000000000..41e1b3483c8 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference2.types @@ -0,0 +1,62 @@ +=== tests/cases/conformance/types/intersection/intersectionTypeInference2.ts === +declare function f(x: { prop: T }): T; +>f : (x: { prop: T; }) => T +>T : T +>x : { prop: T; } +>prop : T +>T : T +>T : T + +declare const a: { prop: string } & { prop: number }; +>a : { prop: string; } & { prop: number; } +>prop : string +>prop : number + +declare const b: { prop: string & number }; +>b : { prop: string & number; } +>prop : string & number + +f(a); // string & number +>f(a) : string & number +>f : (x: { prop: T; }) => T +>a : { prop: string; } & { prop: number; } + +f(b); // string & number +>f(b) : string & number +>f : (x: { prop: T; }) => T +>b : { prop: string & number; } + +// Repro from #18354 + +declare function f2(obj: {[K in keyof T]: T[K]}, key: Key): T[Key]; +>f2 : (obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key] +>T : T +>Key : Key +>T : T +>obj : { [K in keyof T]: T[K]; } +>K : K +>T : T +>T : T +>K : K +>key : Key +>Key : Key +>T : T +>Key : Key + +declare const obj: { a: string } & { b: string }; +>obj : { a: string; } & { b: string; } +>a : string +>b : string + +f2(obj, 'a'); +>f2(obj, 'a') : string +>f2 : (obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key] +>obj : { a: string; } & { b: string; } +>'a' : "a" + +f2(obj, 'b'); +>f2(obj, 'b') : string +>f2 : (obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key] +>obj : { a: string; } & { b: string; } +>'b' : "b" + diff --git a/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts b/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts new file mode 100644 index 00000000000..d32441cfee8 --- /dev/null +++ b/tests/cases/conformance/types/intersection/intersectionTypeInference2.ts @@ -0,0 +1,15 @@ +declare function f(x: { prop: T }): T; + +declare const a: { prop: string } & { prop: number }; +declare const b: { prop: string & number }; + +f(a); // string & number +f(b); // string & number + +// Repro from #18354 + +declare function f2(obj: {[K in keyof T]: T[K]}, key: Key): T[Key]; + +declare const obj: { a: string } & { b: string }; +f2(obj, 'a'); +f2(obj, 'b');