File: genericCallWithGenericSignatureArguments.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 3,677 bytes parent folder | download | duplicates (2)
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/genericCallWithGenericSignatureArguments.ts(18,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
  Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'.
    Property 'y' is missing in type '{ x: number; z?: number; }'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(19,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
  Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'.
    Property 'z' is missing in type '{ x: number; y?: number; }'.


==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.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>(a: (x: T) => T, b: (x: T) => T) {
        var r: (x: T) => T;
        return r;
    }
    
    //var r1 = foo((x: number) => 1, (x: string) => ''); // error
    var r1b = foo((x) => 1, (x) => ''); // {} => {}
    var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object
    var r3 = foo((x: number) => 1, (x: Object) => null); // number => number
    var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number
    
    var a: { x: number; y?: number; };
    var b: { x: number; z?: number; };
    
    var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a
             ~~~
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453:   Type argument candidate '{ x: number; y?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; z?: number; }'.
!!! error TS2453:     Property 'y' is missing in type '{ x: number; z?: number; }'.
    var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b
             ~~~
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453:   Type argument candidate '{ x: number; z?: number; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y?: number; }'.
!!! error TS2453:     Property 'z' is missing in type '{ x: number; y?: number; }'.
    
    function other<T>(x: T) {
        var r6 = foo((a: T) => a, (b: T) => b); // T => T
        var r6b = foo((a) => a, (b) => b); // {} => {}
    }
    
    function other2<T extends Date>(x: T) {
        var r7 = foo((a: T) => a, (b: T) => b); // T => T
        var r7b = foo((a) => a, (b) => b); // {} => {}
        var r8 = r7(null);
        // BUG 835518
        //var r9 = r7(new Date());
    }
    
    
    function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
        var r: (x: T) => T;
        return r;
    }
    
    function other3<T extends RegExp>(x: T) {
        var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date
    }