TypeScript magic
Unioning string literal types with `string` collapses the result to plain `string`, losing autocomplete. Artsy hit this in its palette-mobile React Native design system, where colors should accept named DS tokens like `black100` but also any other color string. Intersecting with an empty object, `string & {}`, produces a type that still accepts any string but is not absorbed in the union. That keeps the literal members visible for editor autocomplete while leaving other values loose.
Related posts
- The shared language of props
Figma mediumAdept
Figma component properties and codebase component props share names but serve different purposes: design props mark visual differences, while code props also carry behaviour, events and data. A case study from a React/TypeScript app built on Material UI shows two Figma button components mapping to five code components layered over a ButtonPrimitive, which used types to make aria-label required for icon-only buttons. The practical advice is to align variant names and casing where possible, mark Figma-only concepts like interaction state with a prefix such as ":state", and accept differences like disabled being a boolean prop in code.
- How to Write Code Without Having to Read It
Shopify Engineering mediumAdeptEngineers can safely change unfamiliar code with minimal reading by letting the compiler, linter and unit tests guide them: locate the entrypoint via user-visible strings (or git bisect for regressions), make the breaking change at the leaf component, then climb the callstack following build errors and sweep back down via lint errors, exhaustive switches and test failures. To make code easier for the next "non-reader," replace comments with enforced checks, wrap primitives in custom types, merge dependent arguments into tagged unions, nested objects or enums, and split decision logic into pure functions so unit tests stay simple. Examples use React Native and TypeScript but the approach generalizes to any typed, tested codebase.
- Creating a React Library for Consistent Data Visualization
Shopify Engineering mediumAdeptShopify's Polaris Viz React charting library replaced scattered per-chart style props with a single `theme` prop backed by a typed Theme record, removing visual inconsistencies across the admin. A PolarisVizProvider context lets consumers override the Default and Light themes or define their own. `createTheme` fills partial themes with library defaults or with a supplied base theme, and `createThemes` guarantees the built-in themes always exist. Individual data series can still override theme colors for data-driven highlighting such as green or red gradients.
- A Gentle Intro to TypeScript
Deno mediumAdeptTypeScript catches the bugs that JavaScript's dynamic typing and implicit type coercion allow, such as add(1, "2") returning "12", by reporting them at compile time instead of at runtime. Annotating function parameters with `: number` is enough for the compiler to reject invalid calls and to infer return and variable types. The usual practice is to add just enough annotations and let inference handle the rest. Node projects need the `typescript` package and `tsc`, while Deno and Vite compile TypeScript transparently.
- Theming the Zalando Design System
Zalando Engineering mediumAdeptZalando built theming into its design system by extracting repeated values into semantic design tokens (e.g. `accent` instead of `orange`) and adding component-level tokens that reference global ones, so themes can change a button's padding without redefining global scales. Colour schemes (default, monochrome-dark, monochrome-light) are first-class within each theme to meet contrast requirements on image-derived banner backgrounds, which raises open questions about native dark mode. Tokens live in TOML files processed by Style Dictionary with custom transforms and formats that emit platform-specific artefacts for web, Android and iOS. Each theme is a partial dictionary deep-merged over the base theme. The tokenization process also simplified the design system and improved cross-platform parity.