Add regression test

This commit is contained in:
Anders Hejlsberg 2017-10-18 16:59:43 -07:00
parent e0c10853ce
commit f8d9079c47
5 changed files with 217 additions and 0 deletions

View file

@ -0,0 +1,44 @@
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: {}; }>; }'.
Types of property 'computed' are incompatible.
Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
Types of property 'baz' are incompatible.
Type 'number' is not assignable to type '() => {}'.
==== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts (1 errors) ====
// Repro from #19316
type ComputedOf<T> = {
[K in keyof T]: () => T[K];
}
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void;
foo({
~
props: { x: 10, y: 20 },
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
computed: {
~~~~~~~~~~~~~~~
bar(): number {
~~~~~~~~~~~~~~~~~~~~~~~
let z = this.bar;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return 42;
~~~~~~~~~~~~~~~~~~~~~~
},
~~~~~~~~~~
baz: 42
~~~~~~~~~~~~~~~
}
~~~~~
});
~
!!! 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: Types of property 'computed' are incompatible.
!!! error TS2345: Type '{ bar(): number; baz: number; }' is not assignable to type 'ComputedOf<{ bar: number; baz: {}; }>'.
!!! error TS2345: Types of property 'baz' are incompatible.
!!! error TS2345: Type 'number' is not assignable to type '() => {}'.

View file

@ -0,0 +1,34 @@
//// [mappedTypeInferenceErrors.ts]
// Repro from #19316
type ComputedOf<T> = {
[K in keyof T]: () => T[K];
}
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void;
foo({
props: { x: 10, y: 20 },
computed: {
bar(): number {
let z = this.bar;
return 42;
},
baz: 42
}
});
//// [mappedTypeInferenceErrors.js]
"use strict";
// Repro from #19316
foo({
props: { x: 10, y: 20 },
computed: {
bar: function () {
var z = this.bar;
return 42;
},
baz: 42
}
});

View file

@ -0,0 +1,55 @@
=== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts ===
// Repro from #19316
type ComputedOf<T> = {
>ComputedOf : Symbol(ComputedOf, Decl(mappedTypeInferenceErrors.ts, 0, 0))
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16))
[K in keyof T]: () => T[K];
>K : Symbol(K, Decl(mappedTypeInferenceErrors.ts, 3, 5))
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16))
>T : Symbol(T, Decl(mappedTypeInferenceErrors.ts, 2, 16))
>K : Symbol(K, Decl(mappedTypeInferenceErrors.ts, 3, 5))
}
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void;
>foo : Symbol(foo, Decl(mappedTypeInferenceErrors.ts, 4, 1))
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21))
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23))
>options : Symbol(options, Decl(mappedTypeInferenceErrors.ts, 6, 27))
>props : Symbol(props, Decl(mappedTypeInferenceErrors.ts, 6, 37))
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21))
>computed : Symbol(computed, Decl(mappedTypeInferenceErrors.ts, 6, 47))
>ComputedOf : Symbol(ComputedOf, Decl(mappedTypeInferenceErrors.ts, 0, 0))
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23))
>ThisType : Symbol(ThisType, Decl(lib.d.ts, --, --))
>P : Symbol(P, Decl(mappedTypeInferenceErrors.ts, 6, 21))
>C : Symbol(C, Decl(mappedTypeInferenceErrors.ts, 6, 23))
foo({
>foo : Symbol(foo, Decl(mappedTypeInferenceErrors.ts, 4, 1))
props: { x: 10, y: 20 },
>props : Symbol(props, Decl(mappedTypeInferenceErrors.ts, 8, 5))
>x : Symbol(x, Decl(mappedTypeInferenceErrors.ts, 9, 12))
>y : Symbol(y, Decl(mappedTypeInferenceErrors.ts, 9, 19))
computed: {
>computed : Symbol(computed, Decl(mappedTypeInferenceErrors.ts, 9, 28))
bar(): number {
>bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15))
let z = this.bar;
>z : Symbol(z, Decl(mappedTypeInferenceErrors.ts, 12, 15))
>this.bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15))
>this : Symbol(__object, Decl(mappedTypeInferenceErrors.ts, 10, 13))
>bar : Symbol(bar, Decl(mappedTypeInferenceErrors.ts, 10, 15))
return 42;
},
baz: 42
>baz : Symbol(baz, Decl(mappedTypeInferenceErrors.ts, 14, 10))
}
});

View file

@ -0,0 +1,64 @@
=== tests/cases/conformance/types/mapped/mappedTypeInferenceErrors.ts ===
// Repro from #19316
type ComputedOf<T> = {
>ComputedOf : ComputedOf<T>
>T : T
[K in keyof T]: () => T[K];
>K : K
>T : T
>T : T
>K : K
}
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void;
>foo : <P, C>(options: { props: P; computed: ComputedOf<C>; } & ThisType<P & C>) => void
>P : P
>C : C
>options : { props: P; computed: ComputedOf<C>; } & ThisType<P & C>
>props : P
>P : P
>computed : ComputedOf<C>
>ComputedOf : ComputedOf<T>
>C : C
>ThisType : ThisType<T>
>P : P
>C : C
foo({
>foo({ props: { x: 10, y: 20 }, computed: { bar(): number { let z = this.bar; return 42; }, baz: 42 }}) : any
>foo : <P, C>(options: { props: P; computed: ComputedOf<C>; } & ThisType<P & C>) => void
>{ props: { x: 10, y: 20 }, computed: { bar(): number { let z = this.bar; return 42; }, baz: 42 }} : { props: { x: number; y: number; }; computed: { bar(): number; baz: number; }; }
props: { x: 10, y: 20 },
>props : { x: number; y: number; }
>{ x: 10, y: 20 } : { x: number; y: number; }
>x : number
>10 : 10
>y : number
>20 : 20
computed: {
>computed : { bar(): number; baz: number; }
>{ bar(): number { let z = this.bar; return 42; }, baz: 42 } : { bar(): number; baz: number; }
bar(): number {
>bar : () => number
let z = this.bar;
>z : () => number
>this.bar : () => number
>this : { bar(): number; baz: number; }
>bar : () => number
return 42;
>42 : 42
},
baz: 42
>baz : number
>42 : 42
}
});

View file

@ -0,0 +1,20 @@
// @strict: true
// Repro from #19316
type ComputedOf<T> = {
[K in keyof T]: () => T[K];
}
declare function foo<P, C>(options: { props: P, computed: ComputedOf<C> } & ThisType<P & C>): void;
foo({
props: { x: 10, y: 20 },
computed: {
bar(): number {
let z = this.bar;
return 42;
},
baz: 42
}
});