File: genericCallWithFunctionTypedArguments2.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 (58 lines) | stat: -rw-r--r-- 2,463 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
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(29,18): error TS2345: Argument of type 'I2<string>' is not assignable to parameter of type 'new (a: 1) => string'.
  Types of parameters 'x' and 'a' are incompatible.
    Type '1' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(40,18): error TS2345: Argument of type 'I2<string>' is not assignable to parameter of type 'new (a: 1) => string'.
  Types of parameters 'x' and 'a' are incompatible.
    Type '1' is not assignable to type 'string'.


==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts (2 errors) ====
    // Generic functions used as arguments for function typed parameters are not used to make inferences from
    // Using construct signature arguments, no errors expected
    
    function foo<T>(x: new(a: T) => T) {
        return new x(null);
    }
    
    interface I {
        new <T>(x: T): T;
    }
    interface I2<T> {
        new (x: T): T;
    }
    var i: I;
    var i2: I2<string>;
    var a: {
        new <T>(x: T): T;
    }
    
    var r = foo(i); // any
    var r2 = foo<string>(i); // string 
    var r3 = foo(i2); // string
    var r3b = foo(a); // any
    
    function foo2<T, U>(x: T, cb: new(a: T) => U) {
        return new cb(x);
    }
    
    var r4 = foo2(1, i2); // error
                     ~~
!!! error TS2345: Argument of type 'I2<string>' is not assignable to parameter of type 'new (a: 1) => string'.
!!! error TS2345:   Types of parameters 'x' and 'a' are incompatible.
!!! error TS2345:     Type '1' is not assignable to type 'string'.
    var r4b = foo2(1, a); // any
    var r5 = foo2(1, i); // any
    var r6 = foo2<string, string>('', i2); // string
    
    function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
        return new cb(x);
    }
    
    var r7 = foo3(null, i, ''); // any
    var r7b = foo3(null, a, ''); // any
    var r8 = foo3(1, i2, 1); // error
                     ~~
!!! error TS2345: Argument of type 'I2<string>' is not assignable to parameter of type 'new (a: 1) => string'.
!!! error TS2345:   Types of parameters 'x' and 'a' are incompatible.
!!! error TS2345:     Type '1' is not assignable to type 'string'.
    var r9 = foo3<string, string>('', i2, ''); // string