【问题标题】:React&TypeScript: What is the type of style sheet object?React&TypeScript:样式表对象的类型是什么?
【发布时间】:2020-12-23 15:59:18
【问题描述】:

对于以下格式的对象,如何指定类型?

    style = {
        height: '200px',
        width: '150px',
        padding: '0',
        backgroundColor: '#fff',
        WebkitFilter: 'drop-shadow(0px 0px 5px #666)',
        filter: 'drop-shadow(0px 0px 5px #666)',
    }

【问题讨论】:

  • React.CSSProperties
  • 它是一个对象,所以你可以使用 Record 类型

标签: css reactjs typescript


【解决方案1】:

您可以像这样提取任何组件的任何道具的类型:

type Style = React.ComponentProps<'div'>['style']

【讨论】:

    猜你喜欢
    • 2017-11-20
    • 1970-01-01
    • 2021-07-20
    • 2021-02-25
    • 2023-03-24
    • 2019-05-10
    • 2019-05-07
    • 2018-03-09
    • 1970-01-01
    相关资源
    最近更新 更多