Skip to content
0:00 / 0:00

#typescript#satisfiesoperator#typewidening

Most TS devs don't understand 'satisfies'

Matt Pocock

429K subscribers • 9 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Matt Pocock

Intermediate. Assumes working knowledge.

70K views2 years ago2 recommendations

Programming languagesTypeScript

Matt Pocock explains how the satisfies operator works in TypeScript and how it prevents type widening while validating types.

Intro Variable annotations What satisfies does When satisfies is GOOD When variable annotations are BAD Outro New Tutorial: totaltypescript.com/tutorials/solving-typescript-errors Become a TypeScript Wizard with my free beginners TypeScript Course: totaltypescript.com/tutorials/beginners-typescript Follow Matt on Twitter twitter.com/mattpocockuk Join the Discord: mattpocock.com/discord

Why it's here

2 people recommend this

What people say. Recommended as a great primer on using the satisfies operator to enforce types without losing narrow type information.

u/heyitsmattwadein r/typescript • Recommends

On “How do I use as const but also enforce type”

Yep, the problem is your `as const` for `examplesWithType` essentially gets "thrown away" because you are typing the variable keyword directly! `satisfies` is when you want to keep some type narrow while also validating it against a wider type. Here is an updated playground with your example, and I also recommend this video for a quick primer on the `satifies` keyword: - link to this video

u/Comfortable_Claim774in r/typescript • Recommends

On “What makes TypeScript impressive for you?”

It's really useful for many cases where you want to avoid type widening but it's hard or impossible to define the correct type. Pretty hard to explain in a reddit comment, but this video by the TS god himself explains it quite well: link to this video