File: genericCallWithGenericSignatureArguments3.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (48 lines) | stat: -rw-r--r-- 3,262 bytes parent folder | download | duplicates (3)
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
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,19): error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => 1' is not assignable to parameter of type '(x: (a: string) => boolean) => (n: Object) => 1'.
  Types of parameters 'a1' and 'x' are incompatible.
    Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,69): error TS2345: Argument of type '(a2: (z: string) => boolean) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => (n: Object) => 1'.
  Type 'number' is not assignable to type '(n: Object) => 1'.


==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ====
    // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, 
    // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
    
    function foo<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
        var r: (x: T) => T;
        return r;
    }
    
    var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any
    var r1ii = foo('', (x) => '', (x) => null); // string => string
    var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string
    var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object
    var r4 = foo(null, (x) => '', (x) => ''); // any => any
    var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object
    
    enum E { A }
    enum F { A }
    
    var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number 
    
    
    function foo2<T, U>(x: T, a: (x: T) => U, b: (x: T) => U) {
        var r: (x: T) => U;
        return r;
    }
    
    var r8 = foo2('', (x) => '', (x) => null); // string => string
    var r9 = foo2(null, (x) => '', (x) => ''); // any => any
    var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object
    
    var x: (a: string) => boolean;
    var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => 1' is not assignable to parameter of type '(x: (a: string) => boolean) => (n: Object) => 1'.
!!! error TS2345:   Types of parameters 'a1' and 'x' are incompatible.
!!! error TS2345:     Type 'boolean' is not assignable to type 'string'.
    var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error
                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(a2: (z: string) => boolean) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => (n: Object) => 1'.
!!! error TS2345:   Type 'number' is not assignable to type '(n: Object) => 1'.