我正在定义以下功能:
const Text = ({
align = 'left',
children,
className,
color = 'middleGrey',
size = 'big',
light = false,
}: Props) => ()
Run Code Online (Sandbox Code Playgroud)
在使用打字稿时,我定义了以下接口:
interface Props {
align: string
children: ReactNode
className: string
color: string
size?: string
light: boolean
}
Run Code Online (Sandbox Code Playgroud)
但这使我每个属性写两次。
有没有更好的方法来编写这种代码?
| 归档时间: |
|
| 查看次数: |
37 次 |
| 最近记录: |