File: genericFunctionParameters.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (59 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
=== 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
>cb : <S>(x: S) => T
>x : S

declare function f2<T>(cb: <S extends number>(x: S) => T): T;
>f2 : <T>(cb: <S extends number>(x: S) => T) => T
>cb : <S extends number>(x: S) => T
>x : S

declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
>f3 : <T>(cb: <S extends S[]>(x: S) => T) => T
>cb : <S extends S[]>(x: S) => T
>x : S

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
>go : <S>(ops: { init(): S; }) => R
>ops : { init(): S; }
>init : () => S

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