File: genericCallWithFunctionTypedArguments.errors.txt

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 (70 lines) | stat: -rw-r--r-- 4,260 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
60
61
62
63
64
65
66
67
68
69
70
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(26,18): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.
  Type 'string' is not assignable to type '1'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,23): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
  Types of parameters 'x' and 'a' are incompatible.
    Type '1' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,23): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
  Types of parameters 'x' and 'a' are incompatible.
    Type '1' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,24): error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
  Types of parameters 'x' and 'a' are incompatible.
    Type '1' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.
  Type 'string' is not assignable to type '1'.


==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts (5 errors) ====
    // Generic functions used as arguments for function typed parameters are not used to make inferences from
    // Using function arguments, no errors expected
    
    function foo<T>(x: (a: T) => T) {
        return x(null);
    }
    
    var r = foo(<U>(x: U) => ''); // {}
    var r2 = foo<string>(<U>(x: U) => ''); // string 
    var r3 = foo(x => ''); // {}
    
    function foo2<T, U>(x: T, cb: (a: T) => U) {
        return cb(x);
    }
    
    var r4 = foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
    var r5 = foo2(1, (a) => ''); // string
    var r6 = foo2<string, number>('', <Z>(a: Z) => 1);
    
    function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
        return cb(x);
    }
    
    var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
    
    var r8 = foo3(1, function (a) { return '' }, 1); // error
                     ~~~~~~~~
!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.
!!! error TS2345:   Type 'string' is not assignable to type '1'.
    var r9 = foo3<number, string>(1, (a) => '', ''); // string
    
    function other<T, U>(t: T, u: U) {
        var r10 = foo2(1, (x: T) => ''); // error
                          ~~~~~~~~~~~~
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
!!! error TS2345:   Types of parameters 'x' and 'a' are incompatible.
!!! error TS2345:     Type '1' is not assignable to type 'T'.
        var r10 = foo2(1, (x) => ''); // string
    
        var r11 = foo3(1, (x: T) => '', ''); // error
                          ~~~~~~~~~~~~
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
!!! error TS2345:   Types of parameters 'x' and 'a' are incompatible.
!!! error TS2345:     Type '1' is not assignable to type 'T'.
        var r11b = foo3(1, (x: T) => '', 1); // error
                           ~~~~~~~~~~~~
!!! error TS2345: Argument of type '(x: T) => string' is not assignable to parameter of type '(a: 1) => string'.
!!! error TS2345:   Types of parameters 'x' and 'a' are incompatible.
!!! error TS2345:     Type '1' is not assignable to type 'T'.
        var r12 = foo3(1, function (a) { return '' }, 1); // error
                          ~~~~~~~~
!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => 1'.
!!! error TS2345:   Type 'string' is not assignable to type '1'.
    }