Open bart-krakowski opened 1 year ago
It'd have to be:
type Unit = `${number}${`ch`|`em`|`px`|`rem`|`vh`|`vw`|`%`}`;
type CSSFunction = `${string}(--${string | number})`; // like `var(--some-var)` or `calc(100% - 220px)`
type StandardLonghandPropertiesValue = Unit | CSSFunction;
at least.
Can't think of other edge cases, but this sort of typing is tough... Even CSSFunction
could be spoofed wrong.
I'd like to make sure the user will be able to provide only a valid strings to a component with this props:
but it allows to provide any string or number:
I've noticed that it could work when I remove
| (string & {});
from this interface:Now I'm able to pass
0
as a type param to theStandardLonghandProperties
interface:As a solution for the issue with
px
,rem
etc I suggest using Template Literal Types: