TypeScript

How to get types running with your System Props

System Props supports TypeScript out of the box, including types for all of the built-in props.

You can use these props to properly type components that have System Props.

Typing a Box

The most common component that you'll likely need to type is the Box component, which will likely use AllSystemProps:

Custom System Props

The library exports SystemProp for making custom system props. You can use this with csstype for CSS property typings.

Autosuggest Theme Values

Like Emotion and styled-components, System Props requires a TS declaration file that defines what the theme shape should be. So alongside your styled.d.ts or emotion.d.ts file, you'll also need a system-props.d.ts file.

Important note about your theme shape! In order for the props' types to work as expected, your theme shape must be a shallow and consistent nesting structure (demonstrated below). While more complex theme structures will still run just fine, the types exported from this library require this limited theme shape to consistently provide accurate and useful suggestions. To help you define this shape, you can extend the SystemPropsTheme interface.

If it's not possible to conform your theme shape to this structure, you can create your own types for System Props. View the source of this package on GitHub to see how it provides the stock types.