File: typeArgumentInferenceWithObjectLiteral.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 (42 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (5)
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
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts(35,43): error TS2345: Argument of type 'E2' is not assignable to parameter of type 'E1'.


==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts (1 errors) ====
    interface Computed<T> {
        read(): T;
        write(value: T);
    }
    
    function foo<T>(x: Computed<T>) { }
    
    var s: string;
    
    // Calls below should infer string for T and then assign that type to the value parameter
    foo({
        read: () => s,
        write: value => s = value
    });
    foo({
        write: value => s = value,
        read: () => s
    });
    
    enum E1 { X }
    enum E2 { X }
    
    // Check that we infer from both a.r and b before fixing T in a.w
    
    declare function f1<T, U>(a: { w: (x: T) => U; r: () => T; }, b: T): U;
    
    var v1: number;
    var v1 = f1({ w: x => x, r: () => 0 }, 0);
    var v1 = f1({ w: x => x, r: () => 0 }, E1.X);
    var v1 = f1({ w: x => x, r: () => E1.X }, 0);
    
    var v2: E1;
    var v2 = f1({ w: x => x, r: () => E1.X }, E1.X);
    
    var v3 = f1({ w: x => x, r: () => E1.X }, E2.X);  // Error
                                              ~~~~
!!! error TS2345: Argument of type 'E2' is not assignable to parameter of type 'E1'.