TypeScript Berlin Meetup #8 - Iván Ovejero - Distributive conditional types

  Рет қаралды 2,534

Prisma

Prisma

Күн бұрын

Пікірлер: 11
@darksinge
@darksinge Жыл бұрын
I started playing with the example code shown at 5:45 and 6:19 and found it to be the opposite. Intellisense gives me access to all methods when using `Cat & Dog`, but only access to the shared `eat()` method when using `Cat | Dog`. Now I'm really confused. The presenter's logic makes perfect sense, but Typescript's compiler is telling me otherwise. Can someone please explain?
@heikoschmale
@heikoschmale Жыл бұрын
Well paid attention. It's just the other way round. Think of union as discriminated unions. Thus on 'Cat | Dog' (read: EITHER cat OR dog), only 'eat()' can be applied safely. It can't be both at the SAME time. On the other side, the intersection 'Cat & Dog' returns a new type with all the properties of 'Cat' and all the properties of 'Dog', because 'Cat & Dog' is both a subset of 'Cat' and a subset of 'Dog'. Thus 'Cat & Dog' can BEHAVE like a 'Cat' and a 'Dog' at the SAME time.
@ivanovejero8421
@ivanovejero8421 Жыл бұрын
Thanks for raising this. You are of course correct. A union of two interfaces produces a smaller interface (fewer methods), which stands for a larger set - membership there only requires the elements in common from both input sets. An intersection of two interfaces produces a larger interface (more methods), which stands for a smaller set - membership there requires all elements from both input sets.
@phoehtaung
@phoehtaung 3 жыл бұрын
using set-theory ideas for types is super helpful!
@dayumnson9769
@dayumnson9769 3 жыл бұрын
wow, great talk! Give this man a medal! Btw. ivov, did yiu ever try out haskells type system?
@ivanovejero8421
@ivanovejero8421 3 жыл бұрын
Thank you! Haskell is on my list to learn.
@heavierthanlight7173
@heavierthanlight7173 2 жыл бұрын
sooooo... "combined" and "shared" would be better names for "unions" and "intersection" exactly how a database uses it.
@yassinebouchoucha
@yassinebouchoucha 2 жыл бұрын
Math is the fundamental of Computer Science not Data Structure and algorithm,
@carloslfu
@carloslfu 2 жыл бұрын
I find TypeScript design a bit flawed in this aspect. It is not what people expect from those operations and it makes trivial stuff non-trivial.
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 112 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 31 МЛН
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 99 МЛН
Infer is easier than you think
13:38
Matt Pocock
Рет қаралды 94 М.
The magic of Rust's type system
9:01
Let's Get Rusty
Рет қаралды 80 М.
KotlinConf 2019: The Power of Types by Danny Preussler
34:49
JetBrains
Рет қаралды 22 М.
"Understanding TypeScript's Structural Type System" by Drew Colthorp
37:47
Strange Loop Conference
Рет қаралды 14 М.
Conditional Types - Advanced TypeScript
23:10
Dmytro Danylov
Рет қаралды 38 М.
Senior Typescript Features You don't Know About - clean-code
13:33
PyO3: From Python to Rust and Back Again (with David Hewitt)
1:34:30
Developer Voices
Рет қаралды 11 М.
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 217 М.
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 112 МЛН