Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing/incorrect React types (SVGProps, HTMLAttributes) #3932

Closed
1 task
galloppinggryphon opened this issue Mar 11, 2023 · 0 comments · Fixed by #4071
Closed
1 task

Missing/incorrect React types (SVGProps, HTMLAttributes) #3932

galloppinggryphon opened this issue Mar 11, 2023 · 0 comments · Fixed by #4071
Labels

Comments

@galloppinggryphon
Copy link

  • Check if updating to the latest Preact version resolves the issue (it did not...)

Describe the bug
I found two problems in the type compatibility layer for React included in preact/compat (in node_modules\preact\compat\src\index.d.ts):

HTMLAttributes: Interface has a required generic parameter (HTMLAttributes<T>) in React, but it is optional in preact/compat, which is an alias for preact.JSX.HTMLAttributes.

SVGProps: Included in React, but missing in preact/compat and preact.JSX.

To Reproduce

package.json

{
  "name": "test",
  "dependencies": {
    "@types/react": "^18.0.28",
    "preact": "^10.13.1",
    "typescript": "^4.9.5"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "paths": {
      //React path aliases
      "react": ["./node_modules/preact/compat/"],
      "react-dom": ["./node_modules/preact/compat/"]
    }
  },
  "include": ["**/*.ts"]
}

Try the code below with and without React path aliases.

SVGProps

import * as React from 'react'

// With path aliases in tsconfig
type SVGProps = React.SVGProps<any> // ❌ Namespace '".../node_modules/preact/src/jsx".JSXInternal' has no exported member 'SVGProps'.

// WITHOUT path aliases in tsconfig
type SVGProps = React.SVGProps<any> //👍 interface React.SVGProps<T>

HTMLAttributes

import * as React from 'react'

// With path aliases in tsconfig
type HTMLAtts = React.HTMLAttributes // 🤔 This should be an error, but isn't

// WITHOUT path aliases in tsconfig
type HTMLAtts = React.HTMLAttributes // ❌ Generic type 'HTMLAttributes<T>' requires 1 type argument(s).

This can also be confirmed by comparing node_modules\@types\react\index.d.ts with node_modules\preact\compat\src\index.d.ts.

Expected behavior
My understanding is that Preact should be interchangeable with React -- a drop-in replacement, at least for a very basic use case. Preact should therefore provide compatible shims for core React types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants