最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to properly use typescript module augmentation for material-ui components? - Stack Overflow

programmeradmin4浏览0评论

I have read the existing answers here and here, but they seem to be outdated.

I have tried the following to augment the type definition for the button ponent, both in a separate typings file (.d.ts) and in the react ponent itself, but to no avail.

declare module "@material-ui/core/Button" {
  export interface ButtonProps {
    to?: string;  
  }
}

When put in the separate .d.ts file, I get a 'JSX element type 'Button' does not have any construct or call signatures.' error.

If put in the same file as the ponent itself, piler just plains that property 'to' does not exist on type 'IntrinsicAttributes & ButtonProps & { children?: ReactNode; }' as if nothing was defined at all.

So I'm wondering about the current correct way to augment ponent type definitions in material-ui (v3.0.2).

Thank you & Cheers

I have read the existing answers here and here, but they seem to be outdated.

I have tried the following to augment the type definition for the button ponent, both in a separate typings file (.d.ts) and in the react ponent itself, but to no avail.

declare module "@material-ui/core/Button" {
  export interface ButtonProps {
    to?: string;  
  }
}

When put in the separate .d.ts file, I get a 'JSX element type 'Button' does not have any construct or call signatures.' error.

If put in the same file as the ponent itself, piler just plains that property 'to' does not exist on type 'IntrinsicAttributes & ButtonProps & { children?: ReactNode; }' as if nothing was defined at all.

So I'm wondering about the current correct way to augment ponent type definitions in material-ui (v3.0.2).

Thank you & Cheers

Share Improve this question asked Sep 5, 2018 at 14:54 saltenhubsaltenhub 6937 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The ButtonProps interface is actually declared in the @material-ui/core/Button/Button module. The following code in your ponent file should work:

declare module "@material-ui/core/Button/Button" {
  export interface ButtonProps {
    to?: string;  
  }
}
发布评论

评论列表(0)

  1. 暂无评论