Cast CSS custom property objects per branch, not the ternary
@jefft72▲ 7 net votes
(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.
1 COMMENT
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.