我已经阅读了现有的答案here和here,但它们似乎已经过时了。
我已尝试以下方法来增加按钮组件的类型定义,无论是在单独的打字文件(.d.ts)和反应组件本身,都无济于事。
declare module "@material-ui/core/Button" {
export interface ButtonProps {
to?: string;
}
}
当放在单独的.d.ts文件中时,我得到一个'JSX元素类型'Button'没有任何构造或调用签名。错误。
如果与组件本身放在同一个文件中,编译器只会抱怨'IntrinsicAttributes&ButtonProps&{children?:ReactNode;好像根本没有定义任何东西。
所以我想知道目前正确的方法来增加material-ui(v3.0.2)中的组件类型定义。
谢谢你和干杯
ButtonProps
接口实际上是在@material-ui/core/Button/Button
模块中声明的。组件文件中的以下代码应该有效:
declare module "@material-ui/core/Button/Button" {
export interface ButtonProps {
to?: string;
}
}