Update tests

This commit is contained in:
Anders Hejlsberg
2018-08-29 14:02:15 -07:00
parent 529ed2d59d
commit c48c3632bd
8 changed files with 10 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ interface Elephant extends Animal { y2 }
var f2: <T extends Animal>(x: T, y: T) => void;
var g2: (g: Giraffe, e: Elephant) => void;
g2 = f2; // valid because both Giraffe and Elephant satisfy the constraint. T is Animal
g2 = f2; // error because Giraffe and Elephant are disjoint types
var h2: (g1: Giraffe, g2: Giraffe) => void;
h2 = f2; // valid because Giraffe satisfies the constraint. It is safe in the traditional contravariant fashion.

View File

@@ -11,6 +11,6 @@ interface B {
var a: A;
var b: B;
// Both ok
// Both errors
a = b;
b = a;

View File

@@ -61,7 +61,7 @@ interface I extends A {
a11: <T extends Base>(x: T, y: T) => T; // ok
a12: <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: <T>(x: { a: T; b: T }) => T; // ok, best common type yields T = {} but that's satisfactory for this signature
a14: <T, U>(x: { a: T; b: U }) => T; // ok
a15: <T>(x: T) => T[]; // ok
a16: <T extends Base>(x: T) => number[]; // ok
a17: <T>(x: (a: T) => T) => T[]; // ok

View File

@@ -44,5 +44,5 @@ interface I extends B {
a11: <T extends Base>(x: T, y: T) => T; // ok
a12: <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: <T>(x: { a: T; b: T }) => T; // ok, best common type yields T = {} but that's satisfactory for this signature
a14: <T, U>(x: { a: T; b: U }) => T; // ok
}

View File

@@ -61,7 +61,7 @@ interface I extends A {
a11: new <T extends Base>(x: T, y: T) => T; // ok
a12: new <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: new <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: new <T>(x: { a: T; b: T }) => T; // ok, best common type yields T = {} but that's satisfactory for this signature
a14: new <T, U>(x: { a: T; b: U }) => T; // ok
a15: new <T>(x: T) => T[]; // ok
a16: new <T extends Base>(x: T) => number[]; // ok
a17: new <T>(x: new (a: T) => T) => T[]; // ok

View File

@@ -44,5 +44,5 @@ interface I extends B {
a11: new <T extends Base>(x: T, y: T) => T; // ok
a12: new <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: new <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: new <T>(x: { a: T; b: T }) => T; // ok, best common type yields T = {} but that's satisfactory for this signature
a14: new <T, U>(x: { a: T; b: U }) => T; // ok
}

View File

@@ -44,5 +44,5 @@ interface I extends B {
a11: new <T extends Base>(x: T, y: T) => T; // ok
a12: new <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: new <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: new <T>(x: { a: T; b: T }) => T; // ok, best common type yields T = {} but that's satisfactory for this signature
a14: new <T, U>(x: { a: T; b: U }) => T; // ok
}

View File

@@ -16,9 +16,9 @@ var a = bar(1, 1, g); // Should be number
var a = baz(1, 1, g); // Should be number
var b: number | string;
var b = foo(g); // Should be number | string
var b = bar(1, "one", g); // Should be number | string
var b = bar("one", 1, g); // Should be number | string
var b = foo(g); // Error, number and string are disjoint types
var b = bar(1, "one", g); // Error, number and string are disjoint types
var b = bar("one", 1, g); // Error, number and string are disjoint types
var b = baz(b, b, g); // Should be number | string
var d: number[] | string[];