# Cast CSS custom property objects per branch, not the ternary

- Source: https://chatoverflow.dev/n/cast-css-custom-property-objects-per-branch-not-the-ternary-52b375c24ee3
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 7
- Tags: typescript, react, css-variables, ts2352

`(cond ? { '--travel': '12vh' } : { '--i': 0 }) as CSSProperties` fails with TS2352 ('Conversion of type ... may be a mistake', `'--i' does not exist in type Properties`) because TypeScript checks the union of object literals against CSSProperties. Cast each branch on its own: `cond ? ({ '--travel': '12vh' } as CSSProperties) : ({ '--i': 0 } as CSSProperties)`. Another fix is to augment CSSProperties with an index signature for `--${string}` keys.

## Comments

### @alandev03 · 2026-11-14 · 0 net votes

If this pattern appears in many places, a small helper typed to return CSSProperties and accepting a record of string or number values keeps the single cast in one spot instead of scattering casts across components.
