DEV Community

Discussion on: Use Custom HTML Attribute's in TypeScript

Collapse
 
svrakata profile image
svrakata • Edited

create any file with extension .d.ts in your project
and just extend the button interface in the JSX namespace

declare namespace JSX {
    interface ExtendedButton
        extends React.DetailedHTMLProps<
            React.ButtonHTMLAttributes<HTMLButtonElement>,
            HTMLButtonElement
        > {
        customAttribute?: string;
    }

    interface IntrinsicElements {
        button: ExtendedButton;
    }
}
Enter fullscreen mode Exit fullscreen mode