4 ms·
Not sure about negation, but humble Typescript lets you use union and intersection types. I am hooked on intersection types in Typescript. It is like mixin hea
by quickthrower2 4y ago
Not sure about negation, but humble
Typescript lets you use union and intersection types.
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.
- ksbrooksjr 4y agoYeah Typescript is great. It doesn't have a negation type per se, but its pretty easy to derive one using the never type [1]. The author of this essay actually explicitly calls out Typescript several times. Some quotes from the paper's conclusion: > 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. [1] https://catchts.com/type-negation https://catchts.com/type-negation
- spiralx 4y agoI called it HasId, there's a withId RxJS operator to go with it that selects from an IdRecord<T> based on an inner observable that emits an ID string. 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).
- ttymck 4y agoIs "nominal typing" the same as structural or duck typing?
- jcparkyn 4y agoNo, they presumably meant to write "structural" because nominal is the opposite.
- klysm 4y agoNominal typing means that two types are different if they have the same structure but a different name. Structural typing is the case where they are considered the same type if they have the same structure.
- deleted 4y ago[deleted]
- quickthrower2 4y agoYeah I do the explicit types for me, even if the compiler can infer the type. Gets that squiggly line close the to root cause.