Master ASSERTION FUNCTIONS in TypeScript - Advanced TypeScript

preview_player
Показать описание
Become a TypeScript Wizard with Matt's upcoming TypeScript Course:

Follow Matt on Twitter

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

These videos are all well presented but I particularly like it when the code sample fits on screen without any scrolling, as in this one (for most of it anyway). It makes it so much easier to keep track of what you're demonstrating.

cccallum
Автор

Those TS video series are amazing. Short and concise videos, teaching something new everytime and with crystal clear examples. Really, high quality channel! Sorry for not subscribing before, definitely deserve it

TheMasterAngel
Автор

I didn't know that. This is insane. I fall in love with typescript. After many years of programming, I realize that the choice of decoupling the type (static) system from the compiled system was a very good solution. It permits that both evolves rapidly. Like ES6 for JS and recursive types for Typescript.

chlbri
Автор

I just have the problem and then I saw this video, so clear and helpful! Thank you so much

pofulu
Автор

Wow, nice! I've read the typescript docs but still didn't know that you can assert on "this". Nice trick!
You have many videos on how to do non-obvious but useful things, I'm now a happy subscriber. Keep going! :)

LennartKolmodin
Автор

I've never seen this before and it's so handy!

TomDoesTech
Автор

Oh, this is amazing! Thanks for sharing

nikensss
Автор

this is unbelivable! never read anything about this, awesome tip

edoardopacciani
Автор

This is fantastic. I've been wondering how to do type guards for instance variables

modernkennnern
Автор

Is it possible to do this for whole class? Or I have to call this assertion in every method ? Thanks.

nickolaizein
Автор

I’m still trying to figure out how this is different from duck typing using just the `is` keyword.

Tushar.Sharma
Автор

Cool. Thank you Matt for your videos.

@mattpocockuk could you help understand can I use assertion for nex function?


const isNullUndefined = <T>(value: T): boolean => [null, undefined].includes(value)

Example of usage
const x: string | null = 'some string'
if (isNullUndefined(x)) return null
console.log(x.toLowerCase())

TS says that x is possibly 'null'

Can I fix it?

MaxiManBW
Автор

this is this.. I didn't know one could do this

maymoonaal-balushi
Автор

like you've said tho, it is important that you actually assert truthfully. is there a way to do inferred structural assertion of the return?

hugodsa
Автор

I have done many assert functions before. But never considered `assert this is this & {something:else}`
That is quite cool.

ColinRichardson
Автор

What if I make the value undefined after the assertion? Will TypeScript notice?

climatechangedoesntbargain
Автор

Would've loved a better explanation about the `this is this` part of the assertion

casraf
Автор

But is it possible to do so for private class attributes ?

pannichita
Автор

Can you clarify the "this is this" meaning please?

cabrinoob
Автор

Anyone know how to do this on a private property?

Liam-eygs