any vs unknown vs never: TypeScript demystified

  Рет қаралды 20,076

Andrew Burgess

Andrew Burgess

Жыл бұрын

Here are a couple links that have helped me understand these types:
ivov.dev/notes/typescript-and...
www.zhenghao.io/posts/ts-never
blog.thoughtspile.tech/2023/0...
My Blog: shaky.sh
My Coding Setup: shaky.sh/tools/

Пікірлер: 45
@kugi7786
@kugi7786 Жыл бұрын
you going over the parts of the language that i didn't know is a huge help, love your videos
@balaganesh3440
@balaganesh3440 Жыл бұрын
That was the most clear and simple explanation of never, I've ever come across. You've really demystified it!
@merotuts9819
@merotuts9819 Жыл бұрын
These types mixed with Set theory makes great sense. Thanks Andrew.
@joel_bio
@joel_bio Ай бұрын
Fantastic perspective
@user-kv2vu4wj9e
@user-kv2vu4wj9e Жыл бұрын
The simple and understandable explanation i have ever seen about typescript types
@helsontaveras7961
@helsontaveras7961 Жыл бұрын
I will like every video you post because they’re all amazing.
@rlkandela
@rlkandela 11 ай бұрын
The exhaustive switch is amazing
@ajgubi19
@ajgubi19 Жыл бұрын
Hands down the best explanation of these three keywords. Loved it! Understood it for the very first time. Thank you! Subscription already paying off!
@javo2432
@javo2432 Жыл бұрын
this video popped out on my recommendation but i watched the whole thing thanks
@JakeAndDaddy
@JakeAndDaddy Жыл бұрын
I’m a hard man to please when it comes to developed KZfaq channels. I’ve seen it and done it all. I’ve got to say though that your content and the way it’s presented is vastly superior to a lot of channels that had exponential growth.
@_briantravis
@_briantravis 6 ай бұрын
amazingly clear explanation, subscribed!
@viridianite
@viridianite Жыл бұрын
You're killing it with these videos, Andrew! I think what many tech videos about languages miss is pragmatism and usage, after all anyone can read the docs and figure out syntax. However you've found a balance between theory and pragmatism.
@Eitrii
@Eitrii 10 ай бұрын
Your explanation just gave me the 'ooOOOooohh!' moment. Liked and subscribed
@dinckelman
@dinckelman Жыл бұрын
Unknown is up there on the godtier list along with the generics
@vOnez212
@vOnez212 4 ай бұрын
Great explanation!
@Luxcium
@Luxcium 11 ай бұрын
The colour grading of those video makes me so happy, the iconic face of Andrew even more and the quintessence of all that being about typescript is making me feel so privilege and lucky to exist in a univers where it is possible to witness any of this
@andrew-burgess
@andrew-burgess 11 ай бұрын
Ha, you're too kind. Colour Grading === whatever comes out of my iPhone.
@Luxcium
@Luxcium 11 ай бұрын
@@andrew-burgess you are filming this with your phone 📱 wow 🤩
@ankitputhran
@ankitputhran Жыл бұрын
Wonderful explanation
@fallingseasy
@fallingseasy Жыл бұрын
Thanks! Great video
@ivaylopetrov9956
@ivaylopetrov9956 6 ай бұрын
Thank you, man! SetTheory rules 💪
@FunctionGermany
@FunctionGermany Жыл бұрын
3:52 i would have mentioned that you probably wouldn't want to write a lot of this kind of manual object parsing code. it gets very messy and you're probably best off using something like zod to parse unknown objects.
@andrew-burgess
@andrew-burgess Жыл бұрын
Oh yeah, absolutely! I just wanted to show how to narrow from unknown to something more concrete. But I’d probably only use this approach for primitives.
@nielsgregersen1351
@nielsgregersen1351 Жыл бұрын
I assume that Record means that the type could also be Record ?
@andrew-burgess
@andrew-burgess Жыл бұрын
Hmm, maybe? Not sure why though, because I already validated that foobar is a number.
@nielsgregersen1351
@nielsgregersen1351 Жыл бұрын
@@andrew-burgess You validated that what was assigned to it at runtime was a number let a :string | number = 42; if ( typeof a === 'number') { console.log(a) }
@yitzchaksviridyuk932
@yitzchaksviridyuk932 Жыл бұрын
@@andrew-burgess This is what ChatGPT says: "The reason why TypeScript still shows val.foobar as unknown inside the if block is due to a limitation in the current version of TypeScript's control flow analysis. Although TypeScript is able to narrow down the type of val based on the if statement condition, it is not yet able to use this information to refine the type of val.foobar to number. Instead, TypeScript conservatively treats val.foobar as unknown to ensure that the code is type-safe." So there you go, one day we'll get there. 😂 Btw, I also checked why Typescript allows us to assign 5 to val.foobar if val.foobar is considered unknown. ChatGPT said that Typescript is performing implicit type assertion in this case.
@dawid_dahl
@dawid_dahl Жыл бұрын
5:20 ”That type of thing.” I saw that you did there.
@tech_channel110
@tech_channel110 29 күн бұрын
well defined
@EnzoAuditore
@EnzoAuditore 4 ай бұрын
Thanks mate
@Luxcium
@Luxcium 11 ай бұрын
So you have me who is passionate about both this content creator and the language *TypeScript* watching a video about something that became somehow really trivial (It was not at the beginning do not worry if you are new to TypeScript and trying to understand *any* can *never* be trivial while it is *unknown* )...
@ayushdixit8993
@ayushdixit8993 5 ай бұрын
Thanks Man....
@JohnWasinger
@JohnWasinger 9 ай бұрын
I bet you never thought you’d fall this deep into your tutorial watching journey.
@clasesutnfrc8699
@clasesutnfrc8699 11 ай бұрын
02:29 How should we use the unknown type?
@coolmind2476
@coolmind2476 2 ай бұрын
Great video. Lets say val is unknown and an object. How to get all components of the unknown object? So instead of checking if foobar in val, I want to get a list of all available components and then check the values of those components.
@Luxcium
@Luxcium 11 ай бұрын
any is the set of all set a cursed concept that is analogous to the nonexistence of both the type checker and set of all set then unknown is the set of all type... never the empty set...
@deatho0ne587
@deatho0ne587 Жыл бұрын
I just wish there was no production code that had the any type. I get it, but man are certain things hard to narrow down. And tryting to add strict mode to the whole code base is just going to make the Bussiness not happy for the tech debt it will incure.
@RozbehSharahi
@RozbehSharahi 5 ай бұрын
The record example might be misleading. In the record example the reason for Record is following: You just verified that foobar is currently a number, but there is no definition that foobar _must_ be a number. So within your if, you can do number operations like "toFixed", but nobody is prohibiting you to write a string or anything else on it (no-type-declaration).
@RozbehSharahi
@RozbehSharahi 5 ай бұрын
To solve this you'd need to create another object Object-B with clear type-definitions and pass the values to it. This way you define that Object-B must have foobar as number.
@juanmiguel431
@juanmiguel431 9 ай бұрын
But I think you can check the type of a variable defined as any type.
@buddy.abc123
@buddy.abc123 Жыл бұрын
I have to subscribe now, been coming across your clear and to the point clips for a while but somehow I didn't subscribe
@soniablanche5672
@soniablanche5672 Жыл бұрын
void vs undefined
@enzodossantos2546
@enzodossantos2546 Жыл бұрын
Void: nothing to return. Undefined: create a variable and don't assign a value.
@soniablanche5672
@soniablanche5672 Жыл бұрын
@@enzodossantos2546 It's confusing because in JavaScript when you return nothing you are actually returning undefined
@ericb8494
@ericb8494 24 күн бұрын
type TODO = any;
Interfaces vs Type Aliases: what's the difference?
10:20
Andrew Burgess
Рет қаралды 21 М.
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 3,5 МЛН
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 37 МЛН
this regex identifies prime numbers (reaction)
10:23
Andrew Burgess
Рет қаралды 113 М.
Learn TypeScript Generics In 13 Minutes
12:52
Web Dev Simplified
Рет қаралды 219 М.
MUST KNOW bashrc customizations to boost productivity in Linux
13:38
How to use generics in TypeScript
11:46
Andrew Burgess
Рет қаралды 35 М.
How to use TypeScript Enums and why not to, maybe
12:43
Andrew Burgess
Рет қаралды 18 М.
will i never understand this? unknown.
12:05
Andrew Burgess
Рет қаралды 3,1 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 363 М.
TypeScript Wizardry: Recursive Template Literals
14:47
Tech Talks with Simon
Рет қаралды 36 М.
The KEY to unions and intersections in TypeScript
4:32
Andrew Burgess
Рет қаралды 9 М.
Main filter..
0:15
CikoYt
Рет қаралды 4,3 МЛН
keren sih #iphone #apple
0:16
Muhammad Arsyad
Рет қаралды 1,6 МЛН
APPLE совершила РЕВОЛЮЦИЮ!
0:39
ÉЖИ АКСЁНОВ
Рет қаралды 633 М.
Девушка и AirPods Max 😳
0:59
ОТЛИЧНИКИ
Рет қаралды 16 М.