Add tests

This commit is contained in:
Anders Hejlsberg 2017-09-21 21:40:31 -07:00
parent afc8a261cc
commit 70e8f7364e
7 changed files with 795 additions and 0 deletions

View File

@ -0,0 +1,25 @@
//// [strictFunctionTypes1.ts]
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
interface Func<T> { (x: T): void }
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
declare function fo(x: Object): void;
declare function fs(x: string): void;
declare function fx(f: (x: "def") => void): void;
const x1 = f1(fo, fs); // (x: string) => void
const x2 = f2("abc", fo, fs); // "abc"
const x3 = f3("abc", fo, fx); // "abc" | "def"
const x4 = f4(fo, fs); // Func<string>
//// [strictFunctionTypes1.js]
"use strict";
var x1 = f1(fo, fs); // (x: string) => void
var x2 = f2("abc", fo, fs); // "abc"
var x3 = f3("abc", fo, fx); // "abc" | "def"
var x4 = f4(fo, fs); // Func<string>

View File

@ -0,0 +1,96 @@
=== tests/cases/compiler/strictFunctionTypes1.ts ===
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 0))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 23))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 28))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 42))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 48))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 0, 65))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 0, 20))
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 79))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
>obj : Symbol(obj, Decl(strictFunctionTypes1.ts, 1, 23))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 1, 30))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 1, 36))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 1, 50))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 1, 56))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 1, 20))
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
>f3 : Symbol(f3, Decl(strictFunctionTypes1.ts, 1, 74))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
>obj : Symbol(obj, Decl(strictFunctionTypes1.ts, 2, 23))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 2, 30))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 2, 36))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 2, 50))
>f : Symbol(f, Decl(strictFunctionTypes1.ts, 2, 56))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 2, 60))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 2, 20))
interface Func<T> { (x: T): void }
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 4, 15))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 4, 21))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 4, 15))
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
>f4 : Symbol(f4, Decl(strictFunctionTypes1.ts, 4, 34))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 6, 23))
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 6, 35))
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
>Func : Symbol(Func, Decl(strictFunctionTypes1.ts, 2, 87))
>T : Symbol(T, Decl(strictFunctionTypes1.ts, 6, 20))
declare function fo(x: Object): void;
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 8, 20))
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
declare function fs(x: string): void;
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 9, 20))
declare function fx(f: (x: "def") => void): void;
>fx : Symbol(fx, Decl(strictFunctionTypes1.ts, 9, 37))
>f : Symbol(f, Decl(strictFunctionTypes1.ts, 10, 20))
>x : Symbol(x, Decl(strictFunctionTypes1.ts, 10, 24))
const x1 = f1(fo, fs); // (x: string) => void
>x1 : Symbol(x1, Decl(strictFunctionTypes1.ts, 12, 5))
>f1 : Symbol(f1, Decl(strictFunctionTypes1.ts, 0, 0))
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
const x2 = f2("abc", fo, fs); // "abc"
>x2 : Symbol(x2, Decl(strictFunctionTypes1.ts, 13, 5))
>f2 : Symbol(f2, Decl(strictFunctionTypes1.ts, 0, 79))
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))
const x3 = f3("abc", fo, fx); // "abc" | "def"
>x3 : Symbol(x3, Decl(strictFunctionTypes1.ts, 14, 5))
>f3 : Symbol(f3, Decl(strictFunctionTypes1.ts, 1, 74))
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
>fx : Symbol(fx, Decl(strictFunctionTypes1.ts, 9, 37))
const x4 = f4(fo, fs); // Func<string>
>x4 : Symbol(x4, Decl(strictFunctionTypes1.ts, 15, 5))
>f4 : Symbol(f4, Decl(strictFunctionTypes1.ts, 4, 34))
>fo : Symbol(fo, Decl(strictFunctionTypes1.ts, 6, 58))
>fs : Symbol(fs, Decl(strictFunctionTypes1.ts, 8, 37))

View File

@ -0,0 +1,102 @@
=== tests/cases/compiler/strictFunctionTypes1.ts ===
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
>T : T
>f1 : (x: T) => void
>x : T
>T : T
>f2 : (x: T) => void
>x : T
>T : T
>x : T
>T : T
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>T : T
>obj : T
>T : T
>f1 : (x: T) => void
>x : T
>T : T
>f2 : (x: T) => void
>x : T
>T : T
>T : T
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
>T : T
>obj : T
>T : T
>f1 : (x: T) => void
>x : T
>T : T
>f2 : (f: (x: T) => void) => void
>f : (x: T) => void
>x : T
>T : T
>T : T
interface Func<T> { (x: T): void }
>Func : Func<T>
>T : T
>x : T
>T : T
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
>T : T
>f1 : Func<T>
>Func : Func<T>
>T : T
>f2 : Func<T>
>Func : Func<T>
>T : T
>Func : Func<T>
>T : T
declare function fo(x: Object): void;
>fo : (x: Object) => void
>x : Object
>Object : Object
declare function fs(x: string): void;
>fs : (x: string) => void
>x : string
declare function fx(f: (x: "def") => void): void;
>fx : (f: (x: "def") => void) => void
>f : (x: "def") => void
>x : "def"
const x1 = f1(fo, fs); // (x: string) => void
>x1 : (x: string) => void
>f1(fo, fs) : (x: string) => void
>f1 : <T>(f1: (x: T) => void, f2: (x: T) => void) => (x: T) => void
>fo : (x: Object) => void
>fs : (x: string) => void
const x2 = f2("abc", fo, fs); // "abc"
>x2 : "abc"
>f2("abc", fo, fs) : "abc"
>f2 : <T>(obj: T, f1: (x: T) => void, f2: (x: T) => void) => T
>"abc" : "abc"
>fo : (x: Object) => void
>fs : (x: string) => void
const x3 = f3("abc", fo, fx); // "abc" | "def"
>x3 : "def" | "abc"
>f3("abc", fo, fx) : "def" | "abc"
>f3 : <T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void) => T
>"abc" : "abc"
>fo : (x: Object) => void
>fx : (f: (x: "def") => void) => void
const x4 = f4(fo, fs); // Func<string>
>x4 : Func<string>
>f4(fo, fs) : Func<string>
>f4 : <T>(f1: Func<T>, f2: Func<T>) => Func<T>
>fo : (x: Object) => void
>fs : (x: string) => void

View File

@ -0,0 +1,271 @@
tests/cases/compiler/strictFunctionTypesErrors.ts(10,1): error TS2322: Type '(x: string) => Object' is not assignable to type '(x: Object) => Object'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(11,1): error TS2322: Type '(x: string) => string' is not assignable to type '(x: Object) => Object'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(13,1): error TS2322: Type '(x: Object) => Object' is not assignable to type '(x: Object) => string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(14,1): error TS2322: Type '(x: string) => Object' is not assignable to type '(x: Object) => string'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(15,1): error TS2322: Type '(x: string) => string' is not assignable to type '(x: Object) => string'.
Types of parameters 'x' and 'x' are incompatible.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(21,1): error TS2322: Type '(x: Object) => Object' is not assignable to type '(x: string) => string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(23,1): error TS2322: Type '(x: string) => Object' is not assignable to type '(x: string) => string'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(33,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, Object>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(34,1): error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, Object>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(36,1): error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<Object, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(37,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(38,1): error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(44,1): error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<string, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(46,1): error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<string, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(57,1): error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<Object, void>, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(58,1): error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<Object, void>, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(61,1): error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, Object>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(62,1): error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, Object>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(65,1): error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(66,1): error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, string>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(67,1): error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(74,1): error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(75,1): error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(76,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(79,1): error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(80,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
Type 'Object' is not assignable to type 'string'.
tests/cases/compiler/strictFunctionTypesErrors.ts(83,1): error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Comparer2<Dog>' is not assignable to type 'Comparer2<Animal>'.
Type 'Animal' is not assignable to type 'Dog'.
==== tests/cases/compiler/strictFunctionTypesErrors.ts (29 errors) ====
export {}
declare let f1: (x: Object) => Object;
declare let f2: (x: Object) => string;
declare let f3: (x: string) => Object;
declare let f4: (x: string) => string;
f1 = f2; // Ok
f1 = f3; // Error
~~
!!! error TS2322: Type '(x: string) => Object' is not assignable to type '(x: Object) => Object'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f1 = f4; // Error
~~
!!! error TS2322: Type '(x: string) => string' is not assignable to type '(x: Object) => Object'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f2 = f1; // Error
~~
!!! error TS2322: Type '(x: Object) => Object' is not assignable to type '(x: Object) => string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f2 = f3; // Error
~~
!!! error TS2322: Type '(x: string) => Object' is not assignable to type '(x: Object) => string'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f2 = f4; // Error
~~
!!! error TS2322: Type '(x: string) => string' is not assignable to type '(x: Object) => string'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f3 = f1; // Ok
f3 = f2; // Ok
f3 = f4; // Ok
f4 = f1; // Error
~~
!!! error TS2322: Type '(x: Object) => Object' is not assignable to type '(x: string) => string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
f4 = f2; // Ok
f4 = f3; // Error
~~
!!! error TS2322: Type '(x: string) => Object' is not assignable to type '(x: string) => string'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
interface Func<T, U> { (x: T): U }
declare let g1: Func<Object, Object>;
declare let g2: Func<Object, string>;
declare let g3: Func<string, Object>;
declare let g4: Func<string, string>;
g1 = g2; // Ok
g1 = g3; // Error
~~
!!! error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, Object>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g1 = g4; // Error
~~
!!! error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, Object>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g2 = g1; // Error
~~
!!! error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<Object, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g2 = g3; // Error
~~
!!! error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<Object, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g2 = g4; // Error
~~
!!! error TS2322: Type 'Func<string, string>' is not assignable to type 'Func<Object, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g3 = g1; // Ok
g3 = g2; // Ok
g3 = g4; // Ok
g4 = g1; // Error
~~
!!! error TS2322: Type 'Func<Object, Object>' is not assignable to type 'Func<string, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
g4 = g2; // Ok
g4 = g3; // Error
~~
!!! error TS2322: Type 'Func<string, Object>' is not assignable to type 'Func<string, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
declare let h1: Func<Func<Object, void>, Object>;
declare let h2: Func<Func<Object, void>, string>;
declare let h3: Func<Func<string, void>, Object>;
declare let h4: Func<Func<string, void>, string>;
h1 = h2; // Ok
h1 = h3; // Ok
h1 = h4; // Ok
h2 = h1; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<Object, void>, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
h2 = h3; // Error
~~
!!! error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<Object, void>, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
h2 = h4; // Ok
h3 = h1; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, Object>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
h3 = h2; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, Object>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h3 = h4; // Ok
h4 = h1; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h4 = h2; // Error
~~
!!! error TS2322: Type 'Func<Func<Object, void>, string>' is not assignable to type 'Func<Func<string, void>, string>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
h4 = h3; // Error
~~
!!! error TS2322: Type 'Func<Func<string, void>, Object>' is not assignable to type 'Func<Func<string, void>, string>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
declare let i1: Func<Object, Func<Object, void>>;
declare let i2: Func<Object, Func<string, void>>;
declare let i3: Func<string, Func<Object, void>>;
declare let i4: Func<string, Func<string, void>>;
i1 = i2; // Error
~~
!!! error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
i1 = i3; // Error
~~
!!! error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i1 = i4; // Error
~~
!!! error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<Object, void>>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i2 = i1; // Ok
i2 = i3; // Error
~~
!!! error TS2322: Type 'Func<string, Func<Object, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i2 = i4; // Error
~~
!!! error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<Object, Func<string, void>>'.
!!! error TS2322: Type 'Object' is not assignable to type 'string'.
i3 = i1; // Ok
i3 = i2; // Error
~~
!!! error TS2322: Type 'Func<Object, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
i3 = i4; // Error
~~
!!! error TS2322: Type 'Func<string, Func<string, void>>' is not assignable to type 'Func<string, Func<Object, void>>'.
!!! error TS2322: Type 'Func<string, void>' is not assignable to type 'Func<Object, void>'.
i4 = i1; // Ok
i4 = i2; // Ok
i4 = i3; // Ok
interface Animal { animal: void }
interface Dog extends Animal { dog: void }
interface Cat extends Animal { cat: void }
interface Comparer1<T> {
compare(a: T, b: T): number;
}
declare let animalComparer1: Comparer1<Animal>;
declare let dogComparer1: Comparer1<Dog>;
animalComparer1 = dogComparer1; // Ok
dogComparer1 = animalComparer1; // Ok
interface Comparer2<T> {
compare: (a: T, b: T) => number;
}
declare let animalComparer2: Comparer2<Animal>;
declare let dogComparer2: Comparer2<Dog>;
animalComparer2 = dogComparer2; // Error
~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Comparer2<Dog>' is not assignable to type 'Comparer2<Animal>'.
!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'.
dogComparer2 = animalComparer2; // Ok

View File

@ -0,0 +1,170 @@
//// [strictFunctionTypesErrors.ts]
export {}
declare let f1: (x: Object) => Object;
declare let f2: (x: Object) => string;
declare let f3: (x: string) => Object;
declare let f4: (x: string) => string;
f1 = f2; // Ok
f1 = f3; // Error
f1 = f4; // Error
f2 = f1; // Error
f2 = f3; // Error
f2 = f4; // Error
f3 = f1; // Ok
f3 = f2; // Ok
f3 = f4; // Ok
f4 = f1; // Error
f4 = f2; // Ok
f4 = f3; // Error
interface Func<T, U> { (x: T): U }
declare let g1: Func<Object, Object>;
declare let g2: Func<Object, string>;
declare let g3: Func<string, Object>;
declare let g4: Func<string, string>;
g1 = g2; // Ok
g1 = g3; // Error
g1 = g4; // Error
g2 = g1; // Error
g2 = g3; // Error
g2 = g4; // Error
g3 = g1; // Ok
g3 = g2; // Ok
g3 = g4; // Ok
g4 = g1; // Error
g4 = g2; // Ok
g4 = g3; // Error
declare let h1: Func<Func<Object, void>, Object>;
declare let h2: Func<Func<Object, void>, string>;
declare let h3: Func<Func<string, void>, Object>;
declare let h4: Func<Func<string, void>, string>;
h1 = h2; // Ok
h1 = h3; // Ok
h1 = h4; // Ok
h2 = h1; // Error
h2 = h3; // Error
h2 = h4; // Ok
h3 = h1; // Error
h3 = h2; // Error
h3 = h4; // Ok
h4 = h1; // Error
h4 = h2; // Error
h4 = h3; // Error
declare let i1: Func<Object, Func<Object, void>>;
declare let i2: Func<Object, Func<string, void>>;
declare let i3: Func<string, Func<Object, void>>;
declare let i4: Func<string, Func<string, void>>;
i1 = i2; // Error
i1 = i3; // Error
i1 = i4; // Error
i2 = i1; // Ok
i2 = i3; // Error
i2 = i4; // Error
i3 = i1; // Ok
i3 = i2; // Error
i3 = i4; // Error
i4 = i1; // Ok
i4 = i2; // Ok
i4 = i3; // Ok
interface Animal { animal: void }
interface Dog extends Animal { dog: void }
interface Cat extends Animal { cat: void }
interface Comparer1<T> {
compare(a: T, b: T): number;
}
declare let animalComparer1: Comparer1<Animal>;
declare let dogComparer1: Comparer1<Dog>;
animalComparer1 = dogComparer1; // Ok
dogComparer1 = animalComparer1; // Ok
interface Comparer2<T> {
compare: (a: T, b: T) => number;
}
declare let animalComparer2: Comparer2<Animal>;
declare let dogComparer2: Comparer2<Dog>;
animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok
//// [strictFunctionTypesErrors.js]
"use strict";
exports.__esModule = true;
f1 = f2; // Ok
f1 = f3; // Error
f1 = f4; // Error
f2 = f1; // Error
f2 = f3; // Error
f2 = f4; // Error
f3 = f1; // Ok
f3 = f2; // Ok
f3 = f4; // Ok
f4 = f1; // Error
f4 = f2; // Ok
f4 = f3; // Error
g1 = g2; // Ok
g1 = g3; // Error
g1 = g4; // Error
g2 = g1; // Error
g2 = g3; // Error
g2 = g4; // Error
g3 = g1; // Ok
g3 = g2; // Ok
g3 = g4; // Ok
g4 = g1; // Error
g4 = g2; // Ok
g4 = g3; // Error
h1 = h2; // Ok
h1 = h3; // Ok
h1 = h4; // Ok
h2 = h1; // Error
h2 = h3; // Error
h2 = h4; // Ok
h3 = h1; // Error
h3 = h2; // Error
h3 = h4; // Ok
h4 = h1; // Error
h4 = h2; // Error
h4 = h3; // Error
i1 = i2; // Error
i1 = i3; // Error
i1 = i4; // Error
i2 = i1; // Ok
i2 = i3; // Error
i2 = i4; // Error
i3 = i1; // Ok
i3 = i2; // Error
i3 = i4; // Error
i4 = i1; // Ok
i4 = i2; // Ok
i4 = i3; // Ok
animalComparer1 = dogComparer1; // Ok
dogComparer1 = animalComparer1; // Ok
animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok

View File

@ -0,0 +1,18 @@
// @strict: true
declare function f1<T>(f1: (x: T) => void, f2: (x: T) => void): (x: T) => void;
declare function f2<T>(obj: T, f1: (x: T) => void, f2: (x: T) => void): T;
declare function f3<T>(obj: T, f1: (x: T) => void, f2: (f: (x: T) => void) => void): T;
interface Func<T> { (x: T): void }
declare function f4<T>(f1: Func<T>, f2: Func<T>): Func<T>;
declare function fo(x: Object): void;
declare function fs(x: string): void;
declare function fx(f: (x: "def") => void): void;
const x1 = f1(fo, fs); // (x: string) => void
const x2 = f2("abc", fo, fs); // "abc"
const x3 = f3("abc", fo, fx); // "abc" | "def"
const x4 = f4(fo, fs); // Func<string>

View File

@ -0,0 +1,113 @@
export {}
// @strict: true
declare let f1: (x: Object) => Object;
declare let f2: (x: Object) => string;
declare let f3: (x: string) => Object;
declare let f4: (x: string) => string;
f1 = f2; // Ok
f1 = f3; // Error
f1 = f4; // Error
f2 = f1; // Error
f2 = f3; // Error
f2 = f4; // Error
f3 = f1; // Ok
f3 = f2; // Ok
f3 = f4; // Ok
f4 = f1; // Error
f4 = f2; // Ok
f4 = f3; // Error
interface Func<T, U> { (x: T): U }
declare let g1: Func<Object, Object>;
declare let g2: Func<Object, string>;
declare let g3: Func<string, Object>;
declare let g4: Func<string, string>;
g1 = g2; // Ok
g1 = g3; // Error
g1 = g4; // Error
g2 = g1; // Error
g2 = g3; // Error
g2 = g4; // Error
g3 = g1; // Ok
g3 = g2; // Ok
g3 = g4; // Ok
g4 = g1; // Error
g4 = g2; // Ok
g4 = g3; // Error
declare let h1: Func<Func<Object, void>, Object>;
declare let h2: Func<Func<Object, void>, string>;
declare let h3: Func<Func<string, void>, Object>;
declare let h4: Func<Func<string, void>, string>;
h1 = h2; // Ok
h1 = h3; // Ok
h1 = h4; // Ok
h2 = h1; // Error
h2 = h3; // Error
h2 = h4; // Ok
h3 = h1; // Error
h3 = h2; // Error
h3 = h4; // Ok
h4 = h1; // Error
h4 = h2; // Error
h4 = h3; // Error
declare let i1: Func<Object, Func<Object, void>>;
declare let i2: Func<Object, Func<string, void>>;
declare let i3: Func<string, Func<Object, void>>;
declare let i4: Func<string, Func<string, void>>;
i1 = i2; // Error
i1 = i3; // Error
i1 = i4; // Error
i2 = i1; // Ok
i2 = i3; // Error
i2 = i4; // Error
i3 = i1; // Ok
i3 = i2; // Error
i3 = i4; // Error
i4 = i1; // Ok
i4 = i2; // Ok
i4 = i3; // Ok
interface Animal { animal: void }
interface Dog extends Animal { dog: void }
interface Cat extends Animal { cat: void }
interface Comparer1<T> {
compare(a: T, b: T): number;
}
declare let animalComparer1: Comparer1<Animal>;
declare let dogComparer1: Comparer1<Dog>;
animalComparer1 = dogComparer1; // Ok
dogComparer1 = animalComparer1; // Ok
interface Comparer2<T> {
compare: (a: T, b: T) => number;
}
declare let animalComparer2: Comparer2<Animal>;
declare let dogComparer2: Comparer2<Dog>;
animalComparer2 = dogComparer2; // Error
dogComparer2 = animalComparer2; // Ok