sirisian / ecmascript-types

ECMAScript Optional Static Typing Proposal http://sirisian.github.io/ecmascript-types/
453 stars 4 forks source link

Define typed switch statements and their behavior and limitations #20

Closed sirisian closed 7 years ago

sirisian commented 7 years ago

Refer to:

let foo:uint32 = 10;
switch (foo)
{
    case 10: // fine
        break;
    case `baz`: // TypeError unexpected string literal, expected uint32
        break;
}

Most integral types have obvious switch behavior. Every floating point type though should be restricted as per convention with most every programming language.

let foo:float32 = 1.23;
switch (foo) // TypeError float32 cannot be used in the switch variable
{
}

Enumerations would be valid based on their assigned type.

sirisian commented 7 years ago

https://github.com/sirisian/ecmascript-types#switch Added the basics. Would need to be fleshed out with the actual specifics later.