I'm using React and Styled Components and I have a function that accepts a string of a css attribute. I want to type it to validate that the string is a valid css attribute (color, background-color, etc...)
function doSomething(cssPropertyName: SomeType) {
}
doSomething('border-color'); // No error
doSomething('non-existing-css-property'); // Should give an error
How can I achieve this?
Thanks!
With: https://github.com/frenic/csstype I think you can simply use:
function doSomething(prop: keyof CSSProperties) {
}
doSomething('borderColor'); // No error
doSomething('non-existing-css-property'); // Should give an error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With