insin / babel-plugin-react-html-attrs

Babel plugin which transforms HTML and SVG attributes on JSX host elements into React-compatible attributes

Home Page:https://astexplorer.net/#/gist/0008d677e8156dab437be51d1fee1757/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to handle typescript issue

PavelPolyakov opened this issue · comments

commented

Hi,

Maybe someone met this before:
image

I really like this plugin comparing to the className, but as long as I started to use it together with typescript - I see this message.

Maybe there are known ways to fix it?

Regards,

@PavelPolyakov did you solve it?

commented

@bySabi no, at the end I started to use className and other pure react properties which are available out of the box.

is a shame.
I really like to copy and paste HTML with class attrs :-)

@PavelPolyakov In the end I could solve it by adding the definition of the class attribute to the React definitions with:

declare module 'react' {
  interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
    // extends React's HTMLAttributes
    class?: string;
  }
}

@tkrotoff maybe this is useful to you too. Related to microsoft/TypeScript#9327

and to put in the typings folder:

import "react";

declare module "react" {
  interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
    // extends React's HTMLAttributes
    class?: string;
  }
}

Tested with a next.js based project