3 ms·
> whose type signature has start and end state As do the reducers. For example the following is a valid type signature. function onToOff(initialState: "on",
by dwohnitmok 6y ago
> whose type signature has start and end state
As do the reducers. For example the following is a valid type signature.
function onToOff(initialState: "on", transition: "toggle"): "off"
In each of the if clauses those are what the types are inferred as, exactly equivalent in type safety to the classes (and more flexible because you can dispatch on action).
I chose string for simplicity (string literals happen to be distinct types on their own, I could easily use anything else other than strings, e.g. interfaces). Heck it could just be integers and be even simpler.
- nsonha 6y agowow a typescript lesson, because no one's ever heard of this > Heck it could just be integers and be even simpler. statement that has zero point, why make them? > As do the reducers like this? A | B | C => B | C | D does that look like a state machine? Because state machine is this A => B & B => C & C => D