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 🙂
More Related Contents:
- Is there a `valueof` similar to `keyof` in TypeScript?
- How to check the object type on runtime in TypeScript?
- Typescript, merge object types?
- How to exclude getter only properties from type in typescript
- How do I declare object value type without declaring key type?
- Typescript: Check “typeof” against custom type
- Specify method’s type without converting the method to property
- How to declare a Fixed length Array in TypeScript
- Is there a way to define type for array with unique items in typescript?
- TypeScript: Accept all Object keys that map to a specific type
- How to undestand relations between types any, unknown, {} and between them and other types?
- Difference between extending and intersecting interfaces in TypeScript?
- TypeScript keyof returning specific type
- Typescript narrowing of keys in objects when passed to function
- Get argument types for function / class constructor
- What is the purpose of bivarianceHack in TypeScript types?
- typescript difference between placement of generics arguments
- Create a global variable in TypeScript
- Way to tell TypeScript compiler Array.prototype.filter removes certain types from an array?
- How to use fetch in TypeScript
- Typescript property does not exist on union type
- Typescript primitive types: any difference between the types “number” and “Number” (is TSC case-insensitive)?
- How to declare a type as nullable in TypeScript?
- How to use Object.values with typescript?
- Typescript: ReturnType of overloaded function
- What TypeScript version is Visual Studio Code using? How to update it?
- Why does TypeScript track mutation of function static properties?
- Array VS Type[] in Typescript
- how to remove properties via mapped type in TypeScript
- Does TypeScript allow type aliases?