2014-07-13 01:04:16 +02:00
|
|
|
//// [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 = {}));
|
2014-08-15 22:18:54 +02:00
|
|
|
var x = 0 /* Red */; // type of 'x' should be 'Colors'
|
|
|
|
var p = x.Green; // error
|
2014-08-16 00:49:09 +02:00
|
|
|
x.toFixed(); // ok
|
2014-08-14 15:21:30 +02:00
|
|
|
// Now with generics
|
2014-07-13 01:04:16 +02:00
|
|
|
function fill(f) {
|
2014-08-16 00:49:09 +02:00
|
|
|
f.Green; // error
|
|
|
|
f.toFixed(); // ok
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|