30 lines
630 B
JavaScript
30 lines
630 B
JavaScript
//// [enumPropertyAccess.ts]
|
|
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
|
|
}
|
|
|
|
//// [enumPropertyAccess.js]
|
|
var Colors;
|
|
(function (Colors) {
|
|
Colors[Colors["Red"] = 0] = "Red";
|
|
Colors[Colors["Green"] = 1] = "Green";
|
|
})(Colors || (Colors = {}));
|
|
var x = 0 /* Red */;// type of 'x' should be 'Colors'
|
|
var p = x.Green;// error
|
|
x.toFixed();
|
|
// Now with generics
|
|
function fill(f) {
|
|
f.Green;
|
|
f.toFixed();
|
|
}
|