File: genericCallWithNonSymmetricSubtypes.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 (48 lines) | stat: -rw-r--r-- 2,992 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
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(12,9): 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/genericCallWithNonSymmetricSubtypes.ts(13,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/genericCallWithNonSymmetricSubtypes.ts (2 errors) ====
    // generic type argument inference where inference leads to two candidates that are both supertypes of all candidates
    // we choose the first candidate so the result is dependent on the order of the arguments provided
    
    function foo<T>(x: T, y: T) {
        var r: T;
        return r;
    }
    
    var a: { x: number; y?: number; };
    var b: { x: number; z?: number; };
    
    var r = foo(a, b); // { x: number; y?: number; };
            ~~~
!!! 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 r2 = foo(b, a); // { x: number; z?: number; };
             ~~~
!!! 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; }'.
    
    var x: { x: number; };
    var y: { x?: number; };
    
    var r3 = foo(a, x); // { x: number; y?: number; };
    var r4 = foo(x, a); // { x: number; };
    
    var r5 = foo(a, y); // { x?: number; };
    var r5 = foo(y, a); // { x?: number; };
    
    var r6 = foo(x, y); // { x?: number; };
    var r6 = foo(y, x); // { x?: number; };
    
    var s1: (x: Object) => string;
    var s2: (x: string) => string;
    
    var r7 = foo(s1, s2); // (x: Object) => string;
    var r8 = foo(s2, s1); // (x: string) => string;