Most TS devs don't understand 'satisfies'

preview_player
Показать описание
00:00 Intro
00:33 Variable annotations
00:53 What satisfies does
02:01 When satisfies is GOOD
02:39 When variable annotations are BAD
03:41 Outro

Become a TypeScript Wizard with my free beginners TypeScript Course:

Follow Matt on Twitter

Join the Discord:

Рекомендации по теме
Комментарии
Автор

I wish you added that 'satisfies' can be combined with 'as const'. It is obvious, but still nice to mention i think

nazaka
Автор

You have made such an impact on the TS community, and enriched us all with your courses, articles and YouTube content. Thank you so much!! I wish us all a wonderful new TypeScript year 🎉

liornz
Автор

This video satisfies any TypeScript developer. Thumbs up for you Matt.

dechobarca
Автор

Before "satisfies" you had to make a choice whether you want something to adhere to a type OR be of the more specific type. With "satisfies" you get both.

nbb
Автор

oh man thankyou I have been looking for this functionality/keyword for like an hour now. So hard to search for if you dont know what it is called. knew I would find it here! I was so sure that the `as` keyword was not the end of the line.

EngineerNick
Автор

`satisfies Partial<MyInterface>` phenomenally useful

ibgib
Автор

You don't know how much you helped me with this. I didn't know about this `satisfies` keyword and I had to write duplicate code to get object constraint with autocompletion as typing out `Record<string, T>` on variable I always loose keys autocompletion.

ShivKumar-qgmt
Автор

typing a word like "satisfies" is satisfying

Dev-Siri
Автор

Thanks for this explanation! In essence, this is like writing:
const name: extends string = "sam";
Which is something I've always wanted to be able to do.

JacobDrebin
Автор

Great explanation Matt! Thanks. Will try to narrow my types further where possible to get more autocompletion.

budivoogt
Автор

Seems like ages since you last popped up in my feed and said "what's up wizards".... welcome back. :)

edgeeffect
Автор

Fantastic content once more, thanks Matt! I appreciate the single-topic video format as well. I'm also looking forward to the book release, especially since the premium TT courses are a bit too expensive for me to purchase at the moment.

mikael.sevigny
Автор

Thank you for this clear explanation. Please continue making such videos focusing on a specific topic only.

SudeeptoDutta
Автор

Takeaway 1: satisfies is a static typing mechanism for literal values (things that are created and assigned inline after an equals sign).

PaulSebastianM
Автор

All the best for 2024 Matt, hope you keep making awesome content for all the wizards!

BoudewijnDanser
Автор

How `as const` plays into this? When to use one over the other or both at the same time?

anj
Автор

I found it useful sometimes when asserting string literals, say I have something like `type State = 'Idle' | 'Succes' | 'Error'`, then in another place in the code I might have `'Idle' satisfies State`, which will assure the type error is caught if I ever change the string literal

There are better ways to handle this typically but in some situations it can be pretty useful

jonathanadamsson
Автор

I started using satisfies more because of its “const” value as well. This is such a good tip. Awesome video as always!

xbsidesx
Автор

I would have loved you to show off satisfies's power a little more at the end by showing one of those massive config objects! It can get really useful when combined with discriminated unions for different types of config options as well

cool_scatter
Автор

This video has been very satisfying, thanks Matt

Cahnisama