Skip to content

Commit dd941e5

Browse files
committed
Add more tests of deferred mapped types
1 parent 5b45cf3 commit dd941e5

8 files changed

Lines changed: 154 additions & 49 deletions

tests/baselines/reference/isomorphicMappedTypeInference.types

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,15 @@ function f2() {
203203

204204
};
205205
let v = unboxify(b);
206-
>v : { a: number; b: string; c: boolean; }
207-
>unboxify(b) : { a: number; b: string; c: boolean; }
206+
>v : { a: {}; b: {}; c: {}; }
207+
>unboxify(b) : { a: {}; b: {}; c: {}; }
208208
>unboxify : <T>(obj: Boxified<T>) => T
209209
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
210210

211211
let x: number = v.a;
212212
>x : number
213213
>v.a : number
214-
>v : { a: number; b: string; c: boolean; }
214+
>v : { a: {}; b: {}; c: {}; }
215215
>a : number
216216
}
217217

@@ -277,11 +277,11 @@ function f4() {
277277

278278
};
279279
b = boxify(unboxify(b));
280-
>b = boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }>
280+
>b = boxify(unboxify(b)) : Boxified<{ a: {}; b: {}; c: {}; }>
281281
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
282-
>boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }>
282+
>boxify(unboxify(b)) : Boxified<{ a: {}; b: {}; c: {}; }>
283283
>boxify : <T>(obj: T) => Boxified<T>
284-
>unboxify(b) : { a: number; b: string; c: boolean; }
284+
>unboxify(b) : { a: {}; b: {}; c: {}; }
285285
>unboxify : <T>(obj: Boxified<T>) => T
286286
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
287287

@@ -338,15 +338,15 @@ function f5(s: string) {
338338

339339
});
340340
let v = unboxify(b);
341-
>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
342-
>unboxify(b) : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
341+
>v : { a: {}; b: {}; c: {}; }
342+
>unboxify(b) : { a: {}; b: {}; c: {}; }
343343
>unboxify : <T>(obj: Boxified<T>) => T
344344
>b : { a: Box<number> | Box<string> | Box<boolean>; b: Box<number> | Box<string> | Box<boolean>; c: Box<number> | Box<string> | Box<boolean>; }
345345

346346
let x: string | number | boolean = v.a;
347347
>x : string | number | boolean
348348
>v.a : string | number | boolean
349-
>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
349+
>v : { a: {}; b: {}; c: {}; }
350350
>a : string | number | boolean
351351
}
352352

@@ -449,20 +449,20 @@ function f10(foo: Foo) {
449449
>Foo : Foo
450450

451451
let x = validate(foo); // { a: number, readonly b: string }
452-
>x : { a: number; readonly b: string; }
453-
>validate(foo) : { a: number; readonly b: string; }
452+
>x : { a: {}; readonly b: {}; }
453+
>validate(foo) : { a: {}; readonly b: {}; }
454454
>validate : <T>(obj: { [P in keyof T]?: T[P] | undefined; }) => T
455455
>foo : Foo
456456

457457
let y = clone(foo); // { a?: number, b: string }
458-
>y : { a?: number | undefined; b: string; }
459-
>clone(foo) : { a?: number | undefined; b: string; }
458+
>y : { a?: {}; b: {}; }
459+
>clone(foo) : { a?: {}; b: {}; }
460460
>clone : <T>(obj: { readonly [P in keyof T]: T[P]; }) => T
461461
>foo : Foo
462462

463463
let z = validateAndClone(foo); // { a: number, b: string }
464-
>z : { a: number; b: string; }
465-
>validateAndClone(foo) : { a: number; b: string; }
464+
>z : { a: {}; b: {}; }
465+
>validateAndClone(foo) : { a: {}; b: {}; }
466466
>validateAndClone : <T>(obj: { readonly [P in keyof T]?: T[P] | undefined; }) => T
467467
>foo : Foo
468468
}
@@ -507,8 +507,8 @@ declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
507507

508508
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
509509
var g1 = applySpec({
510-
>g1 : (...args: any[]) => { sum: number; nested: { mul: string; }; }
511-
>applySpec({ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }}) : (...args: any[]) => { sum: number; nested: { mul: string; }; }
510+
>g1 : (...args: any[]) => { sum: {}; nested: {}; }
511+
>applySpec({ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }}) : (...args: any[]) => { sum: {}; nested: {}; }
512512
>applySpec : <T>(obj: Spec<T>) => (...args: any[]) => T
513513
>{ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }} : { sum: (a: any) => number; nested: { mul: (b: any) => string; }; }
514514

@@ -532,8 +532,8 @@ var g1 = applySpec({
532532

533533
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
534534
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
535-
>g2 : (...args: any[]) => { foo: { bar: { baz: boolean; }; }; }
536-
>applySpec({ foo: { bar: { baz: (x: any) => true } } }) : (...args: any[]) => { foo: { bar: { baz: boolean; }; }; }
535+
>g2 : (...args: any[]) => { foo: {}; }
536+
>applySpec({ foo: { bar: { baz: (x: any) => true } } }) : (...args: any[]) => { foo: {}; }
537537
>applySpec : <T>(obj: Spec<T>) => (...args: any[]) => T
538538
>{ foo: { bar: { baz: (x: any) => true } } } : { foo: { bar: { baz: (x: any) => boolean; }; }; }
539539
>foo : { bar: { baz: (x: any) => boolean; }; }

tests/baselines/reference/keyofAndIndexedAccess.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,8 +1801,8 @@ var hashOfEmpty1 = on({ test: () => {} }); // {}
18011801
>() => {} : () => void
18021802

18031803
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
1804-
>hashOfEmpty2 : { test: boolean; }
1805-
>on({ test: (x: boolean) => {} }) : { test: boolean; }
1804+
>hashOfEmpty2 : { test: {}; }
1805+
>on({ test: (x: boolean) => {} }) : { test: {}; }
18061806
>on : <T>(handlerHash: Handlers<T>) => T
18071807
>{ test: (x: boolean) => {} } : { test: (x: boolean) => void; }
18081808
>test : (x: boolean) => void

tests/baselines/reference/mappedTypeInferenceErrors.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts(9,5): error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: number; baz: {}; }>'.
2-
Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; }'.
1+
tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts(9,5): error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: {}; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: {}; baz: {}; }>'.
2+
Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: {}; baz: {}; }>; }'.
33
Types of property 'computed' are incompatible.
4-
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
4+
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: {}; baz: {}; }>'.
55
Types of property 'baz' are incompatible.
66
Type 'number' is not assignable to type '() => {}'.
77

@@ -35,10 +35,10 @@ tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts(9,5): error TS
3535
~~~~~
3636
});
3737
~
38-
!!! error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: number; baz: {}; }>'.
39-
!!! error TS2345: Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: number; baz: {}; }>; }'.
38+
!!! error TS2345: Argument of type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to parameter of type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: {}; baz: {}; }>; } & ThisType<{ x: number; y: number; } & { bar: {}; baz: {}; }>'.
39+
!!! error TS2345: Type '{ props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }' is not assignable to type '{ props: { x: number; y: number; }; computed: ComputedOf<{ bar: {}; baz: {}; }>; }'.
4040
!!! error TS2345: Types of property 'computed' are incompatible.
41-
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
41+
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: {}; baz: {}; }>'.
4242
!!! error TS2345: Types of property 'baz' are incompatible.
4343
!!! error TS2345: Type 'number' is not assignable to type '() => {}'.
4444

tests/baselines/reference/mappedTypeRecursiveInference.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ declare let a: A;
44
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
55
declare function foo<T>(deep: Deep<T>): T;
66
const out = foo(a);
7+
out.a
8+
out.a.a
9+
out.a.a.a.a.a.a.a
710

811
let xhr: XMLHttpRequest;
912
const out2 = foo(xhr);
13+
out2.responseXML
14+
out2.responseXML.activeElement.className.length
1015

1116

1217
//// [mappedTypeRecursiveInference.js]
1318
var out = foo(a);
19+
out.a;
20+
out.a.a;
21+
out.a.a.a.a.a.a.a;
1422
var xhr;
1523
var out2 = foo(xhr);
24+
out2.responseXML;
25+
out2.responseXML.activeElement.className.length;

tests/baselines/reference/mappedTypeRecursiveInference.symbols

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,57 @@ const out = foo(a);
3030
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
3131
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 1, 11))
3232

33+
out.a
34+
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
35+
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
36+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
37+
38+
out.a.a
39+
>out.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
40+
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
41+
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
42+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
43+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
44+
45+
out.a.a.a.a.a.a.a
46+
>out.a.a.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
47+
>out.a.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
48+
>out.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
49+
>out.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
50+
>out.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
51+
>out.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
52+
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
53+
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
54+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
55+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
56+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
57+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
58+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
59+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
60+
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
61+
3362
let xhr: XMLHttpRequest;
34-
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 6, 3))
63+
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 9, 3))
3564
>XMLHttpRequest : Symbol(XMLHttpRequest, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
3665

3766
const out2 = foo(xhr);
38-
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 7, 5))
67+
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
3968
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
40-
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 6, 3))
69+
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 9, 3))
70+
71+
out2.responseXML
72+
>out2.responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
73+
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
74+
>responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
75+
76+
out2.responseXML.activeElement.className.length
77+
>out2.responseXML.activeElement.className.length : Symbol(length, Decl(lib.es5.d.ts, --, --))
78+
>out2.responseXML.activeElement.className : Symbol(className, Decl(lib.dom.d.ts, --, --))
79+
>out2.responseXML.activeElement : Symbol(activeElement, Decl(lib.dom.d.ts, --, --))
80+
>out2.responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
81+
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
82+
>responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
83+
>activeElement : Symbol(activeElement, Decl(lib.dom.d.ts, --, --))
84+
>className : Symbol(className, Decl(lib.dom.d.ts, --, --))
85+
>length : Symbol(length, Decl(lib.es5.d.ts, --, --))
4186

tests/baselines/reference/mappedTypeRecursiveInference.types

Lines changed: 49 additions & 4 deletions
Large diffs are not rendered by default.

tests/baselines/reference/thisTypeInObjectLiterals2.types

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ p11.bar = p11.bar + 1;
672672
>1 : 1
673673

674674
let p12 = defineProps(p1, {
675-
>p12 : Point & { foo: number; bar: number; }
676-
>defineProps(p1, { foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } }}) : Point & { foo: number; bar: number; }
675+
>p12 : Point & { foo: {}; bar: {}; }
676+
>defineProps(p1, { foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } }}) : Point & { foo: {}; bar: {}; }
677677
>defineProps : <T, U>(obj: T, descs: PropDescMap<U> & ThisType<T>) => T & U
678678
>p1 : Point
679679
>{ foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } }} : { foo: { value: number; }; bar: { get(): number; set(value: number): void; }; }
@@ -716,22 +716,22 @@ let p12 = defineProps(p1, {
716716
p12.foo = p12.foo + 1;
717717
>p12.foo = p12.foo + 1 : number
718718
>p12.foo : number
719-
>p12 : Point & { foo: number; bar: number; }
719+
>p12 : Point & { foo: {}; bar: {}; }
720720
>foo : number
721721
>p12.foo + 1 : number
722722
>p12.foo : number
723-
>p12 : Point & { foo: number; bar: number; }
723+
>p12 : Point & { foo: {}; bar: {}; }
724724
>foo : number
725725
>1 : 1
726726

727727
p12.bar = p12.bar + 1;
728728
>p12.bar = p12.bar + 1 : number
729729
>p12.bar : number
730-
>p12 : Point & { foo: number; bar: number; }
730+
>p12 : Point & { foo: {}; bar: {}; }
731731
>bar : number
732732
>p12.bar + 1 : number
733733
>p12.bar : number
734-
>p12 : Point & { foo: number; bar: number; }
734+
>p12 : Point & { foo: {}; bar: {}; }
735735
>bar : number
736736
>1 : 1
737737

@@ -808,8 +808,8 @@ declare const Vue: new <D, M, P>(options: VueOptions<D, M, P>) => D & M & P;
808808
>P : P
809809

810810
let vue = new Vue({
811-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
812-
>new Vue({ data: () => ({ x: 1, y: 2 }), methods: { f(x: string) { return this.x; } }, computed: { test(): number { return this.x; }, hello: { get() { return "hi"; }, set(value: string) { } } }}) : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
811+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
812+
>new Vue({ data: () => ({ x: 1, y: 2 }), methods: { f(x: string) { return this.x; } }, computed: { test(): number { return this.x; }, hello: { get() { return "hi"; }, set(value: string) { } } }}) : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
813813
>Vue : new <D, M, P>(options: VueOptions<D, M, P>) => D & M & P
814814
>{ data: () => ({ x: 1, y: 2 }), methods: { f(x: string) { return this.x; } }, computed: { test(): number { return this.x; }, hello: { get() { return "hi"; }, set(value: string) { } } }} : { data: () => { x: number; y: number; }; methods: { f(x: string): number; }; computed: { test(): number; hello: { get(): string; set(value: string): void; }; }; }
815815

@@ -833,7 +833,7 @@ let vue = new Vue({
833833

834834
return this.x;
835835
>this.x : number
836-
>this : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
836+
>this : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
837837
>x : number
838838
}
839839
},
@@ -846,7 +846,7 @@ let vue = new Vue({
846846

847847
return this.x;
848848
>this.x : number
849-
>this : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
849+
>this : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
850850
>x : number
851851

852852
},
@@ -870,27 +870,27 @@ let vue = new Vue({
870870
});
871871

872872
vue;
873-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
873+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
874874

875875
vue.x;
876876
>vue.x : number
877-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
877+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
878878
>x : number
879879

880880
vue.f("abc");
881881
>vue.f("abc") : number
882882
>vue.f : (x: string) => number
883-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
883+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
884884
>f : (x: string) => number
885885
>"abc" : "abc"
886886

887887
vue.test;
888888
>vue.test : number
889-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
889+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
890890
>test : number
891891

892892
vue.hello;
893893
>vue.hello : string
894-
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
894+
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
895895
>hello : string
896896

tests/cases/compiler/mappedTypeRecursiveInference.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ declare let a: A;
44
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
55
declare function foo<T>(deep: Deep<T>): T;
66
const out = foo(a);
7+
out.a
8+
out.a.a
9+
out.a.a.a.a.a.a.a
710

811
let xhr: XMLHttpRequest;
912
const out2 = foo(xhr);
13+
out2.responseXML
14+
out2.responseXML.activeElement.className.length

0 commit comments

Comments
 (0)