File: enumPropertyAccess.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (45 lines) | stat: -rw-r--r-- 877 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
=== tests/cases/compiler/enumPropertyAccess.ts ===
enum Colors {
>Colors : Colors

    Red,
>Red : Colors.Red

    Green
>Green : Colors.Green
}

var x = Colors.Red; // type of 'x' should be 'Colors'
>x : Colors
>Colors.Red : Colors.Red
>Colors : typeof Colors
>Red : Colors.Red

var p = x.Green; // error
>p : any
>x.Green : any
>x : Colors.Red
>Green : any

x.toFixed(); // ok
>x.toFixed() : string
>x.toFixed : (fractionDigits?: number) => string
>x : Colors.Red
>toFixed : (fractionDigits?: number) => string

// Now with generics
function fill<B extends Colors>(f: B) {
>fill : <B extends Colors>(f: B) => void
>f : B

    f.Green; // error
>f.Green : any
>f : B
>Green : any

    f.toFixed(); // ok
>f.toFixed() : string
>f.toFixed : (fractionDigits?: number) => string
>f : B
>toFixed : (fractionDigits?: number) => string
}