News for hackers. Stuff that matters.
Re:TypeScript: Control flow analysis for destructured discri... by maxfurman on Wednesday November 03, 2021 @04:20PM (#29099759)
Wow. More impressive work by the Typescript team!

AFAICT this will have the most impact on folks using Typescript with Redux stores and similar dispatchers.I know I would have liked having this feature back when I was doing that work.

Re:TypeScript: Control flow analysis for destructured discri... by acemarke on Wednesday November 03, 2021 @05:23PM (#29100459)
FWIW, our standard recommended Redux usage patterns for the last couple years have specifically _not_ needed switch statements to determine how to handle an action, because our official Redux Toolkit package has a `createSlice` API that lets you define case reducers as simple functions in an object. `createSlice` then generates all the action types internally, generates corresponding action creator functions, and handles calling the right case reducer when that action is dispatched.

Additionally, RTK has been designed to work great with TypeScript. Typically all you need to declare is the type of the state for that slice, and the payload for each reducer's action, and everything else is inferred.

See our Redux docs tutorials for details:

https://redux.js.org/tutorials/essentials/part-2-app-structu...

https://redux.js.org/tutorials/fundamentals/part-8-modern-re...

https://redux.js.org/tutorials/typescript-quick-start

Re:TypeScript: Control flow analysis for destructured discri... by tshaddox on Wednesday November 03, 2021 @04:50PM (#29100091)
I believe this will also obviate a common recommendation to not destructure when using React Query: https://tkdodo.eu/blog/react-query-and-type-script#type-narr...
Re:TypeScript: Control flow analysis for destructured discri... by dragosmocrii on Wednesday November 03, 2021 @04:55PM (#29100143)
Thanks for sharing this. I literally ran into the same issue yesterday, and was wondering why TS can't understand that I am discriminating on the isSucces property.
Re:TypeScript: Control flow analysis for destructured discri... by tkdodo on Friday November 05, 2021 @05:13PM (#29124804)
I’ll definitely update that article once the new TS version is released :)
Re:TypeScript: Control flow analysis for destructured discri... by the_duke on Wednesday November 03, 2021 @04:53PM (#29100118)
Note that this already worked fine by just operating on the field.

Like `if (action.kind === 'x')` / `switch (action.kind)`.

This "only" extends support to destructured discriminators.

Definitely nice to have, but of limited impact.

Re:TypeScript: Control flow analysis for destructured discri... by NaughtyShiba on Wednesday November 03, 2021 @04:29PM (#29099854)
Definitely a help. It should make it easier to use with payloads in postMessage too.