3 ms·
I like you can type check stuff like this: type State = { id: "initial" } | { id: "running", speed: number } const f = (s: State) => { switch (s.id
by throwaway4good 6y ago
I like you can type check stuff like this:
type State = { id: "initial" } | { id: "running", speed: number }
const f = (s: State) => {
switch (s.id) {
case "initial": // s.id available
break;
case "running": // s.id and s.speed available
break;
}
}
The problem with Typescript shows up when people with background in Java or C# starts taking oo design patterns into js-land where they don't really belong (patterns like dependency injection, factories, singletons etc.).