by quickthrower2 · 4y ago · 0 comments
I am hooked on intersection types in Typescript. It is like mixin heaven.
I have a WithId type I use alot that I can tack on to any Firebase record type.
If I had the motivation I could write a generic firebase getter that returns documents as a “T & WithId” (means type T with an additional id:string field)
It decreases the number of types you need to define for one. And lets you lego up various interfaces.
> In this essay I tried to survey the multiple advantages and usages of set-theoretic types in programming.
> ...the need of set-theoretic types naturally arises when trying to fit type-systems on dynamic languages
> The development of languages such as Flow, TypeScript, and Typed Racket is the latest witness of this fact.
Due to nominal typing in TS you don't need to explicitly implement HasId anywhere either, meaning you don't end up with it cluttering up every single type with an ID field (plus imports).
Gets that squiggly line close the to root cause.