File: stringIndexerConstrainsPropertyDeclarations2.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 (69 lines) | stat: -rw-r--r-- 3,540 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(15,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(23,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'.
  Property 'a' is incompatible with index signature.
    Type 'typeof A' is not assignable to type 'A'.
      Property 'foo' is missing in type 'typeof A'.


==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts (7 errors) ====
    // String indexer providing a constraint of a user defined type
    
    class A {
        foo(): string { return ''; }
    }
    
    class B extends A {
        bar(): string { return ''; }
    }
    
    class Foo {
        [x: string]: A;
        a: A; // ok
        b: B; // ok
        c: number; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
        d: string; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
    }
    
    interface Foo2 {
        [x: string]: A;
        a: A; // ok
        b: B; // ok
        c: number; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
        d: string; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
    }
    
    var a: {
        [x: string]: A;
        a: A; // ok
        b: B; // ok
        c: number; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
        d: string; // error
        ~~~~~~~~~~
!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
    };
    
    // error
    var b: { [x: string]: A } = {
        ~
!!! error TS2322: Type '{ a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'.
!!! error TS2322:   Property 'a' is incompatible with index signature.
!!! error TS2322:     Type 'typeof A' is not assignable to type 'A'.
!!! error TS2322:       Property 'foo' is missing in type 'typeof A'.
        a: A,
        b: B
    }