Add tests for type parameter fixing

This commit is contained in:
Jason Freeman 2015-03-13 18:22:30 -07:00
parent a0b96079c2
commit a29b6fe8c7
18 changed files with 440 additions and 0 deletions

View file

@ -0,0 +1,21 @@
//// [typeParameterFixingWithConstraints.ts]
interface IBar {
[barId: string]: any;
}
interface IFoo {
foo<TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar;
}
var foo: IFoo;
foo.foo({ bar: null }, bar => null, bar => null);
//// [typeParameterFixingWithConstraints.js]
var foo;
foo.foo({
bar: null
}, function (bar) {
return null;
}, function (bar) {
return null;
});

View file

@ -0,0 +1,44 @@
=== tests/cases/compiler/typeParameterFixingWithConstraints.ts ===
interface IBar {
>IBar : IBar
[barId: string]: any;
>barId : string
}
interface IFoo {
>IFoo : IFoo
foo<TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar;
>foo : <TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar
>TBar : TBar
>IBar : IBar
>bar : TBar
>TBar : TBar
>bar1 : (bar: TBar) => TBar
>bar : TBar
>TBar : TBar
>TBar : TBar
>bar2 : (bar: TBar) => TBar
>bar : TBar
>TBar : TBar
>TBar : TBar
>TBar : TBar
}
var foo: IFoo;
>foo : IFoo
>IFoo : IFoo
foo.foo({ bar: null }, bar => null, bar => null);
>foo.foo({ bar: null }, bar => null, bar => null) : IBar
>foo.foo : <TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar
>foo : IFoo
>foo : <TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar
>{ bar: null } : { [x: string]: null; bar: null; }
>bar : null
>bar => null : (bar: IBar) => any
>bar : IBar
>bar => null : (bar: IBar) => any
>bar : IBar

View file

@ -0,0 +1,28 @@
//// [typeParameterFixingWithContextSensitiveArguments.ts]
function f<T, U>(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(b, x => x.a, a); // type [A, A]
var d2 = f(b, x => x.a, null); // type [B, A]
var d3 = f(b, x => x.b, null); // type [B, any]
//// [typeParameterFixingWithContextSensitiveArguments.js]
function f(y, f, x) {
return [
y,
f(x)
];
}
var a, b;
var d = f(b, function (x) {
return x.a;
}, a); // type [A, A]
var d2 = f(b, function (x) {
return x.a;
}, null); // type [B, A]
var d3 = f(b, function (x) {
return x.b;
}, null); // type [B, any]

View file

@ -0,0 +1,71 @@
=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts ===
function f<T, U>(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; }
>f : <T, U>(y: T, f: (x: T) => U, x: T) => [T, U]
>T : T
>U : U
>y : T
>T : T
>f : (x: T) => U
>x : T
>T : T
>U : U
>x : T
>T : T
>T : T
>U : U
>[y, f(x)] : [T, U]
>y : T
>f(x) : U
>f : (x: T) => U
>x : T
interface A { a: A; }
>A : A
>a : A
>A : A
interface B extends A { b; }
>B : B
>A : A
>b : any
var a: A, b: B;
>a : A
>A : A
>b : B
>B : B
var d = f(b, x => x.a, a); // type [A, A]
>d : [A, A]
>f(b, x => x.a, a) : [A, A]
>f : <T, U>(y: T, f: (x: T) => U, x: T) => [T, U]
>b : B
>x => x.a : (x: A) => A
>x : A
>x.a : A
>x : A
>a : A
>a : A
var d2 = f(b, x => x.a, null); // type [B, A]
>d2 : [B, A]
>f(b, x => x.a, null) : [B, A]
>f : <T, U>(y: T, f: (x: T) => U, x: T) => [T, U]
>b : B
>x => x.a : (x: B) => A
>x : B
>x.a : A
>x : B
>a : A
var d3 = f(b, x => x.b, null); // type [B, any]
>d3 : [B, any]
>f(b, x => x.b, null) : [B, any]
>f : <T, U>(y: T, f: (x: T) => U, x: T) => [T, U]
>b : B
>x => x.b : (x: B) => any
>x : B
>x.b : any
>x : B
>b : any

View file

@ -0,0 +1,15 @@
tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts(7,25): error TS2345: Argument of type '(x: A) => A' is not assignable to parameter of type '(x: A) => B'.
Type 'A' is not assignable to type 'B'.
==== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts (1 errors) ====
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(a, b, x => x, x => x); // A => A not assignable to A => B
~~~~~~
!!! error TS2345: Argument of type '(x: A) => A' is not assignable to parameter of type '(x: A) => B'.
!!! error TS2345: Type 'A' is not assignable to type 'B'.

View file

@ -0,0 +1,22 @@
//// [typeParameterFixingWithContextSensitiveArguments2.ts]
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(a, b, x => x, x => x); // A => A not assignable to A => B
//// [typeParameterFixingWithContextSensitiveArguments2.js]
function f(y, y1, p, p1) {
return [
y,
p1(y)
];
}
var a, b;
var d = f(a, b, function (x) {
return x;
}, function (x) {
return x;
}); // A => A not assignable to A => B

View file

@ -0,0 +1,15 @@
tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts(7,29): error TS2345: Argument of type '(t2: A) => A' is not assignable to parameter of type '(t2: A) => B'.
Type 'A' is not assignable to type 'B'.
==== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts (1 errors) ====
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
interface A { a: A; }
interface B extends A { b: B; }
var a: A, b: B;
var d = f(a, b, u2 => u2.b, t2 => t2);
~~~~~~~~
!!! error TS2345: Argument of type '(t2: A) => A' is not assignable to parameter of type '(t2: A) => B'.
!!! error TS2345: Type 'A' is not assignable to type 'B'.

View file

@ -0,0 +1,22 @@
//// [typeParameterFixingWithContextSensitiveArguments3.ts]
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
interface A { a: A; }
interface B extends A { b: B; }
var a: A, b: B;
var d = f(a, b, u2 => u2.b, t2 => t2);
//// [typeParameterFixingWithContextSensitiveArguments3.js]
function f(t1, u1, pf1, pf2) {
return [
t1,
pf2(t1)
];
}
var a, b;
var d = f(a, b, function (u2) {
return u2.b;
}, function (t2) {
return t2;
});

View file

@ -0,0 +1,22 @@
//// [typeParameterFixingWithContextSensitiveArguments4.ts]
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(a, b, x => x, x => <any>x); // Type [A, B]
//// [typeParameterFixingWithContextSensitiveArguments4.js]
function f(y, y1, p, p1) {
return [
y,
p1(y)
];
}
var a, b;
var d = f(a, b, function (x) {
return x;
}, function (x) {
return x;
}); // Type [A, B]

View file

@ -0,0 +1,55 @@
=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts ===
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
>f : <T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U) => [T, U]
>T : T
>U : U
>y : T
>T : T
>y1 : U
>U : U
>p : (z: U) => T
>z : U
>U : U
>T : T
>p1 : (x: T) => U
>x : T
>T : T
>U : U
>T : T
>U : U
>[y, p1(y)] : [T, U]
>y : T
>p1(y) : U
>p1 : (x: T) => U
>y : T
interface A { a: A; }
>A : A
>a : A
>A : A
interface B extends A { b; }
>B : B
>A : A
>b : any
var a: A, b: B;
>a : A
>A : A
>b : B
>B : B
var d = f(a, b, x => x, x => <any>x); // Type [A, B]
>d : [A, B]
>f(a, b, x => x, x => <any>x) : [A, B]
>f : <T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U) => [T, U]
>a : A
>b : B
>x => x : (x: B) => B
>x : B
>x : B
>x => <any>x : (x: A) => any
>x : A
><any>x : any
>x : A

View file

@ -0,0 +1,22 @@
//// [typeParameterFixingWithContextSensitiveArguments5.ts]
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
interface A { a: A; }
interface B extends A { b: any; }
var a: A, b: B;
var d = f(a, b, u2 => u2.b, t2 => t2);
//// [typeParameterFixingWithContextSensitiveArguments5.js]
function f(t1, u1, pf1, pf2) {
return [
t1,
pf2(t1)
];
}
var a, b;
var d = f(a, b, function (u2) {
return u2.b;
}, function (t2) {
return t2;
});

View file

@ -0,0 +1,56 @@
=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts ===
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
>f : <T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U) => [T, U]
>T : T
>U : U
>t1 : T
>T : T
>u1 : U
>U : U
>pf1 : (u2: U) => T
>u2 : U
>U : U
>T : T
>pf2 : (t2: T) => U
>t2 : T
>T : T
>U : U
>T : T
>U : U
>[t1, pf2(t1)] : [T, U]
>t1 : T
>pf2(t1) : U
>pf2 : (t2: T) => U
>t1 : T
interface A { a: A; }
>A : A
>a : A
>A : A
interface B extends A { b: any; }
>B : B
>A : A
>b : any
var a: A, b: B;
>a : A
>A : A
>b : B
>B : B
var d = f(a, b, u2 => u2.b, t2 => t2);
>d : [any, B]
>f(a, b, u2 => u2.b, t2 => t2) : [any, B]
>f : <T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U) => [T, U]
>a : A
>b : B
>u2 => u2.b : (u2: B) => any
>u2 : B
>u2.b : any
>u2 : B
>b : any
>t2 => t2 : (t2: any) => any
>t2 : any
>t2 : any

View file

@ -0,0 +1,10 @@
interface IBar {
[barId: string]: any;
}
interface IFoo {
foo<TBar extends IBar>(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar;
}
var foo: IFoo;
foo.foo({ bar: null }, bar => null, bar => null);

View file

@ -0,0 +1,9 @@
function f<T, U>(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(b, x => x.a, a); // type [A, A]
var d2 = f(b, x => x.a, null); // type [B, A]
var d3 = f(b, x => x.b, null); // type [B, any]

View file

@ -0,0 +1,7 @@
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(a, b, x => x, x => x); // A => A not assignable to A => B

View file

@ -0,0 +1,7 @@
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
interface A { a: A; }
interface B extends A { b: B; }
var a: A, b: B;
var d = f(a, b, u2 => u2.b, t2 => t2);

View file

@ -0,0 +1,7 @@
function f<T, U>(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; }
interface A { a: A; }
interface B extends A { b; }
var a: A, b: B;
var d = f(a, b, x => x, x => <any>x); // Type [A, B]

View file

@ -0,0 +1,7 @@
function f<T, U>(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; }
interface A { a: A; }
interface B extends A { b: any; }
var a: A, b: B;
var d = f(a, b, u2 => u2.b, t2 => t2);