Is it possible to restrict number to a certain range

If You have small range, you can always write something like:

type MyRange = 5|6|7|8|9|10

let myVar:MyRange = 4; // oops, error :)

Of course it works just for integers and is ugly as hell :)


No it's not possible. That kind of precise type constraint is not available in typescript (yet?)

Only runtime checks/assertions can achieve that :(