File: overloadresolutionWithConstraintCheckingDeferred.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 (51 lines) | stat: -rw-r--r-- 2,921 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
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,5): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,37): error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'.
  Property 'x' is missing in type 'D'.
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,5): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38): error TS2344: Type 'D' does not satisfy the constraint 'A'.
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
  Types of parameters 'x' and 'x' are incompatible.
    Type 'B' is not assignable to type 'D'.
      Property 'q' is missing in type 'B'.
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,14): error TS2344: Type 'D' does not satisfy the constraint 'A'.


==== tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts (6 errors) ====
    interface A { x }
    interface B { x; y }
    interface C { z }
    interface D { q }
    
    class G<T extends A> {
        constructor(x: T) { }
    }
    
    declare function foo(arg: (x: D) => number): string;
    declare function foo(arg: (x: C) => any): string;
    declare function foo(arg: (x: B) => any): number;
    
    var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
        ~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
                                        ~
!!! error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'.
!!! error TS2345:   Property 'x' is missing in type 'D'.
    
    var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
        ~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
                                         ~~~~~~~~
!!! error TS2344: Type 'D' does not satisfy the constraint 'A'.
    
    var result3: string = foo(x => { // x has type D
                              ~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
!!! error TS2345:   Types of parameters 'x' and 'x' are incompatible.
!!! error TS2345:     Type 'B' is not assignable to type 'D'.
!!! error TS2345:       Property 'q' is missing in type 'B'.
        var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
                 ~~~~~~~~
!!! error TS2344: Type 'D' does not satisfy the constraint 'A'.
        return y;
    });