Add tests

This commit is contained in:
Anders Hejlsberg 2017-10-23 12:36:44 -07:00
parent a87baa2664
commit 414f165df0
4 changed files with 202 additions and 0 deletions

View File

@ -0,0 +1,34 @@
//// [genericFunctionParameters.ts]
declare function f1<T>(cb: <S>(x: S) => T): T;
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
let x1 = f1(x => x); // {}
let x2 = f2(x => x); // number
let x3 = f3(x => x); // Array<any>
// Repro from #19345
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
const x = s(a => a.init()); // x is any, should have been {}
//// [genericFunctionParameters.js]
"use strict";
var x1 = f1(function (x) { return x; }); // {}
var x2 = f2(function (x) { return x; }); // number
var x3 = f3(function (x) { return x; }); // Array<any>
var x = s(function (a) { return a.init(); }); // x is any, should have been {}
//// [genericFunctionParameters.d.ts]
declare function f1<T>(cb: <S>(x: S) => T): T;
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
declare let x1: {};
declare let x2: number;
declare let x3: any[];
declare const s: <R>(go: <S>(ops: {
init(): S;
}) => R) => R;
declare const x: {};

View File

@ -0,0 +1,72 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericFunctionParameters.ts ===
declare function f1<T>(cb: <S>(x: S) => T): T;
>f1 : Symbol(f1, Decl(genericFunctionParameters.ts, 0, 0))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 0, 23))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 0, 28))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 0, 31))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 0, 28))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 0, 20))
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
>f2 : Symbol(f2, Decl(genericFunctionParameters.ts, 0, 46))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 1, 23))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 1, 28))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 1, 46))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 1, 28))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 1, 20))
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
>f3 : Symbol(f3, Decl(genericFunctionParameters.ts, 1, 61))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
>cb : Symbol(cb, Decl(genericFunctionParameters.ts, 2, 23))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 2, 48))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 2, 28))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
>T : Symbol(T, Decl(genericFunctionParameters.ts, 2, 20))
let x1 = f1(x => x); // {}
>x1 : Symbol(x1, Decl(genericFunctionParameters.ts, 4, 3))
>f1 : Symbol(f1, Decl(genericFunctionParameters.ts, 0, 0))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 4, 12))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 4, 12))
let x2 = f2(x => x); // number
>x2 : Symbol(x2, Decl(genericFunctionParameters.ts, 5, 3))
>f2 : Symbol(f2, Decl(genericFunctionParameters.ts, 0, 46))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 5, 12))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 5, 12))
let x3 = f3(x => x); // Array<any>
>x3 : Symbol(x3, Decl(genericFunctionParameters.ts, 6, 3))
>f3 : Symbol(f3, Decl(genericFunctionParameters.ts, 1, 61))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 6, 12))
>x : Symbol(x, Decl(genericFunctionParameters.ts, 6, 12))
// Repro from #19345
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
>s : Symbol(s, Decl(genericFunctionParameters.ts, 10, 13))
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
>go : Symbol(go, Decl(genericFunctionParameters.ts, 10, 21))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 10, 26))
>ops : Symbol(ops, Decl(genericFunctionParameters.ts, 10, 29))
>init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))
>S : Symbol(S, Decl(genericFunctionParameters.ts, 10, 26))
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
>R : Symbol(R, Decl(genericFunctionParameters.ts, 10, 18))
const x = s(a => a.init()); // x is any, should have been {}
>x : Symbol(x, Decl(genericFunctionParameters.ts, 11, 5))
>s : Symbol(s, Decl(genericFunctionParameters.ts, 10, 13))
>a : Symbol(a, Decl(genericFunctionParameters.ts, 11, 12))
>a.init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))
>a : Symbol(a, Decl(genericFunctionParameters.ts, 11, 12))
>init : Symbol(init, Decl(genericFunctionParameters.ts, 10, 35))

View File

@ -0,0 +1,81 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericFunctionParameters.ts ===
declare function f1<T>(cb: <S>(x: S) => T): T;
>f1 : <T>(cb: <S>(x: S) => T) => T
>T : T
>cb : <S>(x: S) => T
>S : S
>x : S
>S : S
>T : T
>T : T
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
>f2 : <T>(cb: <S extends number>(x: S) => T) => T
>T : T
>cb : <S extends number>(x: S) => T
>S : S
>x : S
>S : S
>T : T
>T : T
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
>f3 : <T>(cb: <S extends S[]>(x: S) => T) => T
>T : T
>cb : <S extends S[]>(x: S) => T
>S : S
>Array : T[]
>S : S
>x : S
>S : S
>T : T
>T : T
let x1 = f1(x => x); // {}
>x1 : {}
>f1(x => x) : {}
>f1 : <T>(cb: <S>(x: S) => T) => T
>x => x : <S>(x: S) => S
>x : S
>x : S
let x2 = f2(x => x); // number
>x2 : number
>f2(x => x) : number
>f2 : <T>(cb: <S extends number>(x: S) => T) => T
>x => x : <S extends number>(x: S) => S
>x : S
>x : S
let x3 = f3(x => x); // Array<any>
>x3 : any[]
>f3(x => x) : any[]
>f3 : <T>(cb: <S extends S[]>(x: S) => T) => T
>x => x : <S extends S[]>(x: S) => S
>x : S
>x : S
// Repro from #19345
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
>s : <R>(go: <S>(ops: { init(): S; }) => R) => R
>R : R
>go : <S>(ops: { init(): S; }) => R
>S : S
>ops : { init(): S; }
>init : () => S
>S : S
>R : R
>R : R
const x = s(a => a.init()); // x is any, should have been {}
>x : {}
>s(a => a.init()) : {}
>s : <R>(go: <S>(ops: { init(): S; }) => R) => R
>a => a.init() : <S>(a: { init(): S; }) => S
>a : { init(): S; }
>a.init() : S
>a.init : () => S
>a : { init(): S; }
>init : () => S

View File

@ -0,0 +1,15 @@
// @strict: true
// @declaration: true
declare function f1<T>(cb: <S>(x: S) => T): T;
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
let x1 = f1(x => x); // {}
let x2 = f2(x => x); // number
let x3 = f3(x => x); // Array<any>
// Repro from #19345
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
const x = s(a => a.init()); // x is any, should have been {}