Back to Browse

assertUnreachable techniques with Ryan from the TypeScript team

5.4K views
Jan 12, 2024
8:55

Perhaps you've heard of `assertUnreachable` or even used the `ts-assert-unreachable` npm. For most of us, we first saw it on a Stack Overflow post (https://stackoverflow.com/questions/39419170/how-do-i-check-that-a-switch-block-is-exhaustive-in-typescript/39419171#39419171) from Ryan Cavanaugh from the TypeScript team. So then when this topic came up in our theorycrafting video on T[number], we thought "who better to do a short theorycraft video on assertUnreachable than Ryan himself?!". So.. here you go! Enjoy! 0:00 what `assertUnreachable` does 0:41 where'd the idea come from? 1:29 the problem it solves 1:56 how `assertUnreachable` works 2:20 thinking about `noImplicitReturns` being in the mix 3:31 interesting subtleties 4:30 should unreachable code even be allowed? 6:02 other variations on `assertUnreachable` 7:20 variations on adding a message or not throwing To see the code from this episode, check out the TheoryCraft GitHub: https://github.com/MichiganTypeScript/theorycraft/blob/main/episodes/assert-unreachable/code.tsx _______ Twitter: https://twitter.com/MiTypeScript Mastodon: https://fosstodon.org/@MichiganTypeScript BlueSky: https://bsky.app/profile/michigantypescript.bsky.social Threads: https://www.threads.net/@michigantypescript Instagram: https://www.instagram.com/michigantypescript TikTok: https://www.tiktok.com/@michigantypescript Discord: https://discord.michigantypescript.com GitHub: https://github.com/MichiganTypeScript SoundCloud: https://soundcloud.com/michigan-typescript

Download

1 formats

Video Formats

360pmp424.1 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

assertUnreachable techniques with Ryan from the TypeScript team | NatokHD