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!
(prop: keyof CSSProperties) => ...Though you'd need to provideborderColorinstead ofborder-color(for example).