14 lines
256 B
TypeScript
14 lines
256 B
TypeScript
|
enum Colors {
|
||
|
Red,
|
||
|
Green
|
||
|
}
|
||
|
|
||
|
var x = Colors.Red; // type of 'x' should be 'Colors'
|
||
|
var p = x.Green; // error
|
||
|
x.toFixed(); // ok
|
||
|
|
||
|
// Now with generics
|
||
|
function fill<B extends Colors>(f: B) {
|
||
|
f.Green; // error
|
||
|
f.toFixed(); // ok
|
||
|
}
|