So satisfies checks to see what the actual type is and then does some type checking in the background to see what it could match on that type and narrows it for you? If so that is insanely cool.
Declaring a constant that follows a type but still get type inference. This way, any « typeof » you do on your constant gets the infered type, not the « base » one. This then can be used in mapped types to create new types based on your constant. I’m using this to create a constant where I map attributes from my API to my app data, then use mapped type to create the types for that data. This way, anything I add in my mapping contant is also added on my types and I can start using them right away.
@@d.ilnicki Second allows more flexible casts. const x = true as false; // Compiles without error const y: false = true; // Type 'true' is not assignable to type 'false'.
That cant be right, they all satisfy the type, and each way would ensure that check...it appears that satisfies does not mask the actual type. The other methods override ...somehow
I wish you made a whole js course in mini shorts format.
Read about some killer use cases for `satisfies` in my full article: www.builder.io/blog/satisfies-operator
Lmfao I was struggling with this for days and now I randomly found the sollution while watching shorts
Nuff said 👏
Dang, this is a good example.
make more videos on typescript
Same applies for generic T extends Color vs. Color
These videos are soo good
Love your videos
So satisfies checks to see what the actual type is and then does some type checking in the background to see what it could match on that type and narrows it for you? If so that is insanely cool.
Very nice 👍
Ok but remove satisfies on bleu and you get the same result🙄
Why not just `const blue:Color`
Where do u learn TS, other than courses. I prefer reading online.
It is a game changer, but how can we use it in function params?
Why would I set types for a constant variable?
To make sure they confirm to the necessary shape when authoring (including things like autocomplete in your IDE), as well as better refactoring etc
Autocompletion.
Feels like footgun.
Can you teach us how you do your subtitles?
I always uses the first method
Means you never wrote tsx files before?
Wouldn't casting as one of the type from the union type work the same way?
I guess it's just more explicit
Usecase of satisfies?
Configuration ua-cam.com/video/xPhGANCF6Pc/v-deo.html
@@Steve8708 you earned a subscriber
Declaring a constant that follows a type but still get type inference. This way, any « typeof » you do on your constant gets the infered type, not the « base » one.
This then can be used in mapped types to create new types based on your constant.
I’m using this to create a constant where I map attributes from my API to my app data, then use mapped type to create the types for that data.
This way, anything I add in my mapping contant is also added on my types and I can start using them right away.
There're lots. Wery useful when object will be passed to generic and transformed somehow depending on actual shape.
So would it be correct to say that the first two are type annotations but the third one is a type assertion?
Other way around
JS word feels like DLC
They give you a feature then another one that does the whole work for y’a
That's bad code
Never do #2 if possible
Never give any advices if you want to provide no explanation.
@@d.ilnicki You lose type information without adding any safety or other benefit.
@@d.ilnicki Second allows more flexible casts.
const x = true as false; // Compiles without error
const y: false = true; // Type 'true' is not assignable to type 'false'.
kinda obvious
So satisfies literally checks if it satisfies the type
That cant be right, they all satisfy the type, and each way would ensure that check...it appears that satisfies does not mask the actual type.
The other methods override ...somehow
Typescript has become a joke with these sematics.
if this is backend code, i'd rather not play russian roulette with types
Why do they invent useless language features like this?
If you think they're useless then you're a bad developer. Maybe learn something yeah?
strict. typing. avoid all of this.
First and third are absolutely strict.