Enumerated values in TypeScript v.2.0


#1

TypeScript 2.0 will have an Ada-like feature:

https://blogs.msdn.microsoft.com/typescript/2016/08/30/announcing-typescript-2-0-rc/

We wanted to give some more love to types other than just string. In 2.0, each unique boolean, number, and enum member will have its own type!

type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
let nums: Digit[] = [1, 2, 4, 8];

// Error! '16' isn't a 'Digit'!
nums.push(16);

Similar stuff is good for a safety-conscious system language :slight_smile:


#2

That would be nice indeed :wink:
But it involves changes to the core type system and also syntax / grammar.

I’m not sure if that would be possible with “macro 2.0” (compiler plugin)…


#3

I think the syntax doesn’t need breaking changes, just incremental changes. Ada-style enumerated values can be very useful in Rust.