File: unionTypeInference.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 (38 lines) | stat: -rw-r--r-- 1,216 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
tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts(9,15): error TS2345: Argument of type '2' is not assignable to parameter of type 'string | 1'.


==== tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts (1 errors) ====
    // Verify that inferences made *to* a type parameter in a union type are secondary
    // to inferences made directly to that type parameter
    
    function f<T>(x: T, y: string|T): T {
        return x;
    }
    
    var a1: number;
    var a1 = f(1, 2);
                  ~
!!! error TS2345: Argument of type '2' is not assignable to parameter of type 'string | 1'.
    var a2: number;
    var a2 = f(1, "hello");
    var a3: number;
    var a3 = f(1, a1 || "hello");
    var a4: any;
    var a4 = f(undefined, "abc");
    
    function g<T>(value: [string, T]): T {
        return value[1];
    }
    
    var b1: boolean;
    var b1 = g(["string", true]);
    
    function h<T>(x: string|boolean|T): T {
        return typeof x === "string" || typeof x === "boolean" ? undefined : x;
    }
    
    var c1: number;
    var c1 = h(5);
    var c2: string;
    var c2 = h("abc");