File: switchStatements.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 (63 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (4)
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
tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,20): error TS2678: Type '{ id: number; name: string; }' is not comparable to type 'C'.
  Object literal may only specify known properties, and 'name' does not exist in type 'C'.


==== tests/cases/conformance/statements/switchStatements/switchStatements.ts (1 errors) ====
    module M {
        export function fn(x: number) {
            return '';
        }
    }
    
    var x: any;
    switch (x) {
        case '':
        case 12:
        case true:
        case null:
        case undefined:
        case new Date(12):
        case new Object():
        case /[a-z]/:
        case[]:
        case {}:
        case { id: 12 }:
        case['a']:
        case typeof x:
        case typeof M:
        case M.fn(1):
        case <T>(x: number) => '':
        case (<T>(x: number) => '')(2):
        default:
    }
    
    // basic assignable check, rest covered in tests for 'assignement compatibility'
    class C { id: number; }
    class D extends C { name: string }
    
    switch (new C()) {
        case new D():
        case { id: 12, name: '' }:
                       ~~~~~~~~
!!! error TS2678: Type '{ id: number; name: string; }' is not comparable to type 'C'.
!!! error TS2678:   Object literal may only specify known properties, and 'name' does not exist in type 'C'.
        case new C():
    }
    
    switch ('') { }
    switch (12) { }
    switch (true) { }
    switch (null) { }
    switch (undefined) { }
    switch (new Date(12)) { }
    switch (new Object()) { }
    switch (/[a-z]/) { }
    switch ([]) { }
    switch ({}) { }
    switch ({ id: 12 }) { }
    switch (['a']) { }
    switch (<T>(x: number) => '') { }
    switch ((<T>(x: T) => '')(1)) { }