preact icon indicating copy to clipboard operation
preact copied to clipboard

[compat types] - issue with the element's type like button, that gets any instead of ButtonHTMLAttributes

Open samsam-ahmadi opened this issue 1 year ago • 3 comments

  • [x] Check if updating to the latest Preact version resolves the issue

Describe the bug The issue is with some conflicts type of compat with React types, when other libraries trying to using the react types inner like: styled-components.

For some elements react has special type like this line: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f701ddcb5bec7d89238b8f1b9d362a20ff9c8e94/types/react/v17/index.d.ts#L2048

So as you can see there is an error for h1 but for button there isn't and it takes any

Screenshot 2023-08-15 at 15 14 27

So i checked the styled-component that give the button this type.

button: Styled<"web", "button", import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, import("../types").BaseObject>;

But after using aliases of compat, it will be something like this:

button: Styled<"web", "button", **any**, import("../types").BaseObject>;

Because styled component trying to access to ButtonHTMLAttributes, but this type doesn't exist in the compact so it takes any.

To Reproduce

If possible, please provide a CodeSandbox/Codepen that demonstrates the issue. You can use the following template: https://codesandbox.io/s/preact-x-preact-cli-3-starter-vj285y2rn3

I can't do it, Because for displaying the errors needs more typescript configuration but i explain it here:

Steps to reproduce the behavior:

  1. create a vite + typescript + preact+ styled-components
  2. npm i -D vite-plugin-checker
  3. Add this config to vite plugins. => checker({ typescript: true })
  4. Also this one
  5. preact({ babel: { plugins: [ [ "babel-plugin-styled-components", { pure: true, displayName: false, fileName: false, }, ], ], }, }),

Then add ThemeProvider and styled.d.ts like this codesandbox. https://codesandbox.io/s/interesting-hooks-5m8kvr?file=/src/App.tsx

After that If you create those components in the screenshot you can see h1 has correct type but button doesn't have.

Expected behavior What should have happened when following the steps above?

samsam-ahmadi avatar Aug 15 '23 21:08 samsam-ahmadi

Has this issue been resolved?

victor-williams avatar Aug 29 '23 06:08 victor-williams

@victor-williams I'm waiting for approval, If you can't wait, You can take the new codes and put into the reactCompat.d.ts in your project until this merge.

samsam-ahmadi avatar Sep 01 '23 08:09 samsam-ahmadi

I'm also blocked on this.

wong2 avatar Sep 22 '23 04:09 wong2