【问题标题】:What type my className props need to have in React component using TypeScript?使用 TypeScript 在 React 组件中我的 className 道具需要具有什么类型?
【发布时间】:2022-01-22 06:48:27
【问题描述】:

我在键入我的 className 道具方面需要帮助。我已经尝试过使用 HTMLAttributes

className: React.HTMLAttributes<HTMLButtonElement>;

当我尝试在 className 属性中使用我的道具时出现此错误,例如“button className={className}”

"Type 'HTMLAttributes<HTMLButtonElement>' is not assignable to type 'string'."

当我在 className 道具中使用顺风类时会出现此错误

Type 'string' has no properties in common with type 'HTMLAttributes<HTMLButtonElement>'.

【问题讨论】:

  • 你能检查一下这个thread的解决方案吗?

标签: reactjs typescript tailwind-css


【解决方案1】:

答案写在你的问题中:

“类型 'HTMLAttributes' 不可分配给类型 'string'。”

类型“string”与类型“HTMLAttributes”没有共同的属性

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多