File: genericSpecializations3.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 (69 lines) | stat: -rw-r--r-- 3,182 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
tests/cases/compiler/genericSpecializations3.ts(9,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
  Type '(x: string) => string' is not assignable to type '(x: number) => number'.
    Types of parameters 'x' and 'x' are incompatible.
      Type 'number' is not assignable to type 'string'.
tests/cases/compiler/genericSpecializations3.ts(28,1): error TS2322: Type 'StringFoo2' is not assignable to type 'IntFoo'.
  Types of property 'foo' are incompatible.
    Type '(x: string) => string' is not assignable to type '(x: number) => number'.
      Types of parameters 'x' and 'x' are incompatible.
        Type 'number' is not assignable to type 'string'.
tests/cases/compiler/genericSpecializations3.ts(29,1): error TS2322: Type 'IntFoo' is not assignable to type 'StringFoo2'.
  Types of property 'foo' are incompatible.
    Type '(x: number) => number' is not assignable to type '(x: string) => string'.
      Types of parameters 'x' and 'x' are incompatible.
        Type 'string' is not assignable to type 'number'.


==== tests/cases/compiler/genericSpecializations3.ts (3 errors) ====
    interface IFoo<T> {
        foo(x: T): T;
    }
    
    var iFoo: IFoo<number>;
    iFoo.foo(1);
    
    class IntFooBad implements IFoo<number> { // error
        foo(x: string): string { return null; }
        ~~~
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
!!! error TS2416:   Type '(x: string) => string' is not assignable to type '(x: number) => number'.
!!! error TS2416:     Types of parameters 'x' and 'x' are incompatible.
!!! error TS2416:       Type 'number' is not assignable to type 'string'.
    }
    
    var intFooBad: IntFooBad;
    
    class IntFoo implements IFoo<number> {
        foo(x: number): number { return null; }
    }
    
    var intFoo: IntFoo;
    
    class StringFoo2 implements IFoo<string> {
        foo(x: string): string { return null; }
    }
    
    var stringFoo2: StringFoo2;
    stringFoo2.foo("hm");
    
    
    intFoo = stringFoo2; // error
    ~~~~~~
!!! error TS2322: Type 'StringFoo2' is not assignable to type 'IntFoo'.
!!! error TS2322:   Types of property 'foo' are incompatible.
!!! error TS2322:     Type '(x: string) => string' is not assignable to type '(x: number) => number'.
!!! error TS2322:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322:         Type 'number' is not assignable to type 'string'.
    stringFoo2 = intFoo; // error
    ~~~~~~~~~~
!!! error TS2322: Type 'IntFoo' is not assignable to type 'StringFoo2'.
!!! error TS2322:   Types of property 'foo' are incompatible.
!!! error TS2322:     Type '(x: number) => number' is not assignable to type '(x: string) => string'.
!!! error TS2322:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
    
    
    class StringFoo3 implements IFoo<string> { // error
        foo<T>(x: T): T { return null; }
    }
    var stringFoo3: StringFoo3;