5 ms·
Or, maybe the original code was actually totally fine and in fact the simplest and most obvious solution.
by incrudible 5y ago
Or, maybe the original code was actually totally fine and in fact the simplest and most obvious solution.
- PartiallyTyped 5y agoLiterals 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.