Add more tests of deferred mapped types

This commit is contained in:
Nathan Shively-Sanders 2017-12-14 15:11:49 -08:00
parent 5b45cf3db1
commit dd941e5665
8 changed files with 154 additions and 49 deletions

View file

@ -203,15 +203,15 @@ function f2() {
};
let v = unboxify(b);
>v : { a: number; b: string; c: boolean; }
>unboxify(b) : { a: number; b: string; c: boolean; }
>v : { a: {}; b: {}; c: {}; }
>unboxify(b) : { a: {}; b: {}; c: {}; }
>unboxify : <T>(obj: Boxified<T>) => T
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
let x: number = v.a;
>x : number
>v.a : number
>v : { a: number; b: string; c: boolean; }
>v : { a: {}; b: {}; c: {}; }
>a : number
}
@ -277,11 +277,11 @@ function f4() {
};
b = boxify(unboxify(b));
>b = boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }>
>b = boxify(unboxify(b)) : Boxified<{ a: {}; b: {}; c: {}; }>
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
>boxify(unboxify(b)) : Boxified<{ a: number; b: string; c: boolean; }>
>boxify(unboxify(b)) : Boxified<{ a: {}; b: {}; c: {}; }>
>boxify : <T>(obj: T) => Boxified<T>
>unboxify(b) : { a: number; b: string; c: boolean; }
>unboxify(b) : { a: {}; b: {}; c: {}; }
>unboxify : <T>(obj: Boxified<T>) => T
>b : { a: Box<number>; b: Box<string>; c: Box<boolean>; }
@ -338,15 +338,15 @@ function f5(s: string) {
});
let v = unboxify(b);
>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
>unboxify(b) : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
>v : { a: {}; b: {}; c: {}; }
>unboxify(b) : { a: {}; b: {}; c: {}; }
>unboxify : <T>(obj: Boxified<T>) => T
>b : { a: Box<number> | Box<string> | Box<boolean>; b: Box<number> | Box<string> | Box<boolean>; c: Box<number> | Box<string> | Box<boolean>; }
let x: string | number | boolean = v.a;
>x : string | number | boolean
>v.a : string | number | boolean
>v : { a: string | number | boolean; b: string | number | boolean; c: string | number | boolean; }
>v : { a: {}; b: {}; c: {}; }
>a : string | number | boolean
}
@ -449,20 +449,20 @@ function f10(foo: Foo) {
>Foo : Foo
let x = validate(foo); // { a: number, readonly b: string }
>x : { a: number; readonly b: string; }
>validate(foo) : { a: number; readonly b: string; }
>x : { a: {}; readonly b: {}; }
>validate(foo) : { a: {}; readonly b: {}; }
>validate : <T>(obj: { [P in keyof T]?: T[P] | undefined; }) => T
>foo : Foo
let y = clone(foo); // { a?: number, b: string }
>y : { a?: number | undefined; b: string; }
>clone(foo) : { a?: number | undefined; b: string; }
>y : { a?: {}; b: {}; }
>clone(foo) : { a?: {}; b: {}; }
>clone : <T>(obj: { readonly [P in keyof T]: T[P]; }) => T
>foo : Foo
let z = validateAndClone(foo); // { a: number, b: string }
>z : { a: number; b: string; }
>validateAndClone(foo) : { a: number; b: string; }
>z : { a: {}; b: {}; }
>validateAndClone(foo) : { a: {}; b: {}; }
>validateAndClone : <T>(obj: { readonly [P in keyof T]?: T[P] | undefined; }) => T
>foo : Foo
}
@ -507,8 +507,8 @@ declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
var g1 = applySpec({
>g1 : (...args: any[]) => { sum: number; nested: { mul: string; }; }
>applySpec({ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }}) : (...args: any[]) => { sum: number; nested: { mul: string; }; }
>g1 : (...args: any[]) => { sum: {}; nested: {}; }
>applySpec({ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }}) : (...args: any[]) => { sum: {}; nested: {}; }
>applySpec : <T>(obj: Spec<T>) => (...args: any[]) => T
>{ sum: (a: any) => 3, nested: { mul: (b: any) => "n" }} : { sum: (a: any) => number; nested: { mul: (b: any) => string; }; }
@ -532,8 +532,8 @@ var g1 = applySpec({
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
>g2 : (...args: any[]) => { foo: { bar: { baz: boolean; }; }; }
>applySpec({ foo: { bar: { baz: (x: any) => true } } }) : (...args: any[]) => { foo: { bar: { baz: boolean; }; }; }
>g2 : (...args: any[]) => { foo: {}; }
>applySpec({ foo: { bar: { baz: (x: any) => true } } }) : (...args: any[]) => { foo: {}; }
>applySpec : <T>(obj: Spec<T>) => (...args: any[]) => T
>{ foo: { bar: { baz: (x: any) => true } } } : { foo: { bar: { baz: (x: any) => boolean; }; }; }
>foo : { bar: { baz: (x: any) => boolean; }; }

View file

@ -1801,8 +1801,8 @@ var hashOfEmpty1 = on({ test: () => {} }); // {}
>() => {} : () => void
var hashOfEmpty2 = on({ test: (x: boolean) => {} }); // { test: boolean }
>hashOfEmpty2 : { test: boolean; }
>on({ test: (x: boolean) => {} }) : { test: boolean; }
>hashOfEmpty2 : { test: {}; }
>on({ test: (x: boolean) => {} }) : { test: {}; }
>on : <T>(handlerHash: Handlers<T>) => T
>{ test: (x: boolean) => {} } : { test: (x: boolean) => void; }
>test : (x: boolean) => void

View file

@ -1,7 +1,7 @@
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: {}; }>'.
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: {}; }>; }'.
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: {}; }>'.
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: {}; }>; }'.
Types of property 'computed' are incompatible.
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: {}; baz: {}; }>'.
Types of property 'baz' are incompatible.
Type 'number' is not assignable to type '() => {}'.
@ -35,10 +35,10 @@ tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts(9,5): error TS
~~~~~
});
~
!!! 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: {}; }>'.
!!! 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: {}; }>; }'.
!!! 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: {}; }>'.
!!! 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: {}; }>; }'.
!!! error TS2345: Types of property 'computed' are incompatible.
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: {}; baz: {}; }>'.
!!! error TS2345: Types of property 'baz' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type '() => {}'.

View file

@ -4,12 +4,22 @@ declare let a: A;
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
declare function foo<T>(deep: Deep<T>): T;
const out = foo(a);
out.a
out.a.a
out.a.a.a.a.a.a.a
let xhr: XMLHttpRequest;
const out2 = foo(xhr);
out2.responseXML
out2.responseXML.activeElement.className.length
//// [mappedTypeRecursiveInference.js]
var out = foo(a);
out.a;
out.a.a;
out.a.a.a.a.a.a.a;
var xhr;
var out2 = foo(xhr);
out2.responseXML;
out2.responseXML.activeElement.className.length;

View file

@ -30,12 +30,57 @@ const out = foo(a);
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 1, 11))
out.a
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
out.a.a
>out.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
out.a.a.a.a.a.a.a
>out.a.a.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out.a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>out : Symbol(out, Decl(mappedTypeRecursiveInference.ts, 4, 5))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
>a : Symbol(a, Decl(mappedTypeRecursiveInference.ts, 0, 13))
let xhr: XMLHttpRequest;
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 6, 3))
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 9, 3))
>XMLHttpRequest : Symbol(XMLHttpRequest, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
const out2 = foo(xhr);
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 7, 5))
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
>foo : Symbol(foo, Decl(mappedTypeRecursiveInference.ts, 2, 45))
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 6, 3))
>xhr : Symbol(xhr, Decl(mappedTypeRecursiveInference.ts, 9, 3))
out2.responseXML
>out2.responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
>responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
out2.responseXML.activeElement.className.length
>out2.responseXML.activeElement.className.length : Symbol(length, Decl(lib.es5.d.ts, --, --))
>out2.responseXML.activeElement.className : Symbol(className, Decl(lib.dom.d.ts, --, --))
>out2.responseXML.activeElement : Symbol(activeElement, Decl(lib.dom.d.ts, --, --))
>out2.responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
>out2 : Symbol(out2, Decl(mappedTypeRecursiveInference.ts, 10, 5))
>responseXML : Symbol(responseXML, Decl(lib.dom.d.ts, --, --))
>activeElement : Symbol(activeElement, Decl(lib.dom.d.ts, --, --))
>className : Symbol(className, Decl(lib.dom.d.ts, --, --))
>length : Symbol(length, Decl(lib.es5.d.ts, --, --))

File diff suppressed because one or more lines are too long

View file

@ -672,8 +672,8 @@ p11.bar = p11.bar + 1;
>1 : 1
let p12 = defineProps(p1, {
>p12 : Point & { foo: number; bar: number; }
>defineProps(p1, { foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } }}) : Point & { foo: number; bar: number; }
>p12 : Point & { foo: {}; bar: {}; }
>defineProps(p1, { foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } }}) : Point & { foo: {}; bar: {}; }
>defineProps : <T, U>(obj: T, descs: PropDescMap<U> & ThisType<T>) => T & U
>p1 : Point
>{ 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, {
p12.foo = p12.foo + 1;
>p12.foo = p12.foo + 1 : number
>p12.foo : number
>p12 : Point & { foo: number; bar: number; }
>p12 : Point & { foo: {}; bar: {}; }
>foo : number
>p12.foo + 1 : number
>p12.foo : number
>p12 : Point & { foo: number; bar: number; }
>p12 : Point & { foo: {}; bar: {}; }
>foo : number
>1 : 1
p12.bar = p12.bar + 1;
>p12.bar = p12.bar + 1 : number
>p12.bar : number
>p12 : Point & { foo: number; bar: number; }
>p12 : Point & { foo: {}; bar: {}; }
>bar : number
>p12.bar + 1 : number
>p12.bar : number
>p12 : Point & { foo: number; bar: number; }
>p12 : Point & { foo: {}; bar: {}; }
>bar : number
>1 : 1
@ -808,8 +808,8 @@ declare const Vue: new <D, M, P>(options: VueOptions<D, M, P>) => D & M & P;
>P : P
let vue = new Vue({
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>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; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>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: {}; }
>Vue : new <D, M, P>(options: VueOptions<D, M, P>) => D & M & P
>{ 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; }; }; }
@ -833,7 +833,7 @@ let vue = new Vue({
return this.x;
>this.x : number
>this : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>this : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>x : number
}
},
@ -846,7 +846,7 @@ let vue = new Vue({
return this.x;
>this.x : number
>this : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>this : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>x : number
},
@ -870,27 +870,27 @@ let vue = new Vue({
});
vue;
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
vue.x;
>vue.x : number
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>x : number
vue.f("abc");
>vue.f("abc") : number
>vue.f : (x: string) => number
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>f : (x: string) => number
>"abc" : "abc"
vue.test;
>vue.test : number
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>test : number
vue.hello;
>vue.hello : string
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: number; hello: string; }
>vue : { x: number; y: number; } & { f(x: string): number; } & { test: {}; hello: {}; }
>hello : string

View file

@ -4,6 +4,11 @@ declare let a: A;
type Deep<T> = { [K in keyof T]: Deep<T[K]> }
declare function foo<T>(deep: Deep<T>): T;
const out = foo(a);
out.a
out.a.a
out.a.a.a.a.a.a.a
let xhr: XMLHttpRequest;
const out2 = foo(xhr);
out2.responseXML
out2.responseXML.activeElement.className.length