At Artsy, we love TypeScript. We use it in most of our node/web/mobile repos. Today, I want to talk about a specific case we found while trying to make our types more strict on palette-mobile, which is our Design System for React Native.
Check this out:
const welp: "hello" | "world" | string // `welp` is of type `string`.
Like the comment says, even though we have two specific strings, the fact that
we do a union with
welp have a type of just
string. This is
"world" are strings, and the union tends to go to
the type that includes the most.
Think of set theory and bubbles.