File: genericCallWithConstraintsTypeArgumentInference2.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 (46 lines) | stat: -rw-r--r-- 1,016 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
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithConstraintsTypeArgumentInference2.ts ===
// Generic call with parameters of T and U, U extends T, no parameter of type U

function foo<T, U extends T>(t: T) {
>foo : <T, U extends T>(t: T) => U
>t : T

    var u: U;
>u : U

    return u;
>u : U
}

var r = foo(1); // ok
>r : number
>foo(1) : number
>foo : <T, U extends T>(t: T) => U
>1 : 1

var r2 = foo(null); // {}
>r2 : {}
>foo(null) : {}
>foo : <T, U extends T>(t: T) => U
>null : null

var r3 = foo(new Object()); // {}
>r3 : {}
>foo(new Object()) : {}
>foo : <T, U extends T>(t: T) => U
>new Object() : Object
>Object : ObjectConstructor

var r4 = foo<Date, Date>(1); // error
>r4 : any
>foo<Date, Date>(1) : any
>foo : <T, U extends T>(t: T) => U
>1 : 1

var r5 = foo<Date, Date>(new Date()); // no error
>r5 : Date
>foo<Date, Date>(new Date()) : Date
>foo : <T, U extends T>(t: T) => U
>new Date() : Date
>Date : DateConstructor