Conversation

This: type Course = {name: string} & ( {started: true, lastInteraction: Date} | {started: false} ) Not this: type Course = name: string, started: boolean, lastInteraction: Date | undefined } The first frees me from worrying about an undefined lastInteractionTime.
23
676
It's interesting that I've known this in theory for a long time, but I keep catching myself making this mistake. I usually notice because logic gets confusing, so I switch over to the type definitions and try to find the too-broad type causing the confusion.
1
27
Also, this example shows why I like TypeScript's type system and syntax. Easy type unions and intersections, plus literals being their own types, make this kind of type definition easy and terse.
2
58
Also, human brains are genetically wired for infix operators, which you can see from the fact that every verb in this tweet is an infix operator connecting two operands on either side, combined with the fact that natural language grammar wasn't designed by anti-Lisp illuminati.
9
44
doesn't (... ? ... : ...) from C qualify? (and, in a similar way, "if ... then ... else ..." from ML & Haskell; not to mention arbitrary mixfix operators in Agda & Idris)
1
4
apart from potential trouble with tokenization rules (eg. "<|39|>" being parsed as a single token), I think Agda & Idris's mixfix operators let you do that!
1
4