Skip to content

Commit 773c9a7

Browse files
committed
Add tests
1 parent c538f1f commit 773c9a7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,11 @@ var g1 = applySpec({
145145
});
146146

147147
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
148-
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
148+
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
149+
150+
// Repro from #12633
151+
152+
const foo = <T>(object: T, partial: Partial<T>) => object;
153+
let o = {a: 5, b: 7};
154+
foo(o, {b: 9});
155+
o = foo(o, {b: 9});

tests/cases/conformance/types/mapped/mappedTypeErrors.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,21 @@ function f11<T>() {
6767
function f12<T>() {
6868
var x: { [P in keyof T]: T[P] };
6969
var x: { [P in keyof T]: T[P][] }; // Error
70+
}
71+
72+
// Check that inferences to mapped types are secondary
73+
74+
declare function objAndReadonly<T>(primary: T, secondary: Readonly<T>): T;
75+
declare function objAndPartial<T>(primary: T, secondary: Partial<T>): T;
76+
77+
function f20() {
78+
let x1 = objAndReadonly({ x: 0, y: 0 }, { x: 1 }); // Error
79+
let x2 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1 });
80+
let x3 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
81+
}
82+
83+
function f21() {
84+
let x1 = objAndPartial({ x: 0, y: 0 }, { x: 1 });
85+
let x2 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1 });
86+
let x3 = objAndPartial({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
7087
}

0 commit comments

Comments
 (0)