Override Third Party Type Definitions in TypeScript

382 Views Asked by At

My doubt is how to override a type definition provided by a third party package (in my case @mui) using only d.ts file

USE CASE:

I want to indicate for all Button Components that the id prop is required, so any dev that use any Button will know that needs to provide an Id

I have tried a file *d.ts with something like this:

declare module '@mui/material/ButtonBase' {
 interface ExtendButtonBaseTypeMap<M extends OverridableTypeMap> {
     props: { id: string }
     defaultComponent: M['defaultComponent']
 }
}

but did not work :(

For chakra-ui I know that this works:

declare module React {
 interface ButtonHTMLAttributes {
     id: string
 }
}
0

There are 0 best solutions below