4 ms·
Literals should be avoided since they can get mistyped unless the compiler can enforce that.
by PartiallyTyped 5y ago
Literals should be avoided since they can get mistyped unless the compiler can enforce that.
- incrudible 5y agoThe TypeScript compiler can enforce that, notice how the type annotation in the example is `'admin' | 'customer'`, not `string`. It's also possible to give this type a name: type UserCreationType = 'admin' | 'customer'
- PartiallyTyped 5y agoI see. Then I am joining the club where the first one was perfectly fine.
- beebeepka 5y agoYup, typescript is pretty good when it comes to this kind of stuff. This was one of the very few things I tried when I first started with TS.