[英]if you want all css properties as a type in typescript what do you put?
StyleProps is used for size and colour. StyleProps 用于大小和颜色。
I would prefer it was all styles.我宁愿全是 styles。
This is so I can hand down the styles directly into the specific part of the component.这样我就可以将 styles 直接传递到组件的特定部分。
what do I put in to mean the types of all CSS properties?我输入什么来表示所有 CSS 属性的类型?
how do I change the styles to be all styles?如何将 styles 全部更改为 styles?
interface StyleProps{
color?: string;
size?: string;
}
interface TextButtonProps {
buttonStyle?: styleProps;
click: () => void;
text: string;
}
const TextButton = ({ buttonStyle, text, click }: TextButtonProps) => {
You can extend the built-in type CSSStyleDeclaration
(ES6 lib typings):您可以扩展内置类型CSSStyleDeclaration
(ES6 库类型):
interface StyleProps extends Partial<CSSStyleDeclaration> {
color?: string; // ! not necessary
size?: string;
}
interface TextButtonProps {
buttonStyle?: StyleProps;
click: () => void;
text: string;
}
const TextButton = ({ buttonStyle, text, click }: TextButtonProps) => {
Partial
is used because the built-in type's properties are all required.使用Partial
是因为内置类型的属性都是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.