I have the following code snippet:
type Color = string;
interface Props {
color: Color;
text: string;
}
function Badge(props: Props) {
return `<div style="color:${props.color}">${props.text}</div>`;
}
var badge = Badge({
color: '#F00',
text: 'Danger'
});
console.log(badge);
Playground
I am trying to get a build error if the color is not valid, for example:
var badge = Badge({
color: 'rgba(100, 100, 100)',
text: 'Danger'
});
Is there a way to define Colorso that it only allows strings matching one of the following patterns?
#FFF#FFFFFFrgb(5, 5, 5)rgba(5, 5, 5, 1)hsa(5, 5, 5)
I understand that there are such colors as redand white, but this can make the answer difficult if I Colorcan accept them.
source
share