Skip to content

fix: preact does not export Element #64

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

Merged
merged 1 commit into from
Jun 10, 2022

Conversation

maxbeatty
Copy link
Contributor

What: bug in types. preact does not export Element

Why: causing issues in TypeScript project (and errors with eslint)

How: remove type declaration and depend on global Element

Checklist:

  • Documentation added
  • Tests
  • Typescript definitions updated
  • Ready to be merged

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Jun 10, 2022

Element is exported by the JSX bindings only, is it found as a global when you remove the import? https://github.com/preactjs/preact/blob/master/src/jsx.d.ts#L29

@maxbeatty
Copy link
Contributor Author

my project is using:

  • "typescript": "^4.7.3",
  • "preact": "^10.7.3",

with v3.2.1, I'm seeing this error:

❯ tsc
node_modules/@testing-library/preact/types/index.d.ts:3:41 - error TS2305: Module '"preact"' has no exported member 'Element'.

3 import { ComponentChild, ComponentType, Element } from 'preact'

downgrading to v3.1.2 fixes the error. I was also able to verify by manually removing the Element import.

to your point, maybe a more appropriate fix is something like:

- import { ComponentChild, ComponentType, Element } from 'preact'
+ import { ComponentChild, ComponentType, JSX } from 'preact'

export * from '@testing-library/dom'

export type RenderResult<Q extends Queries = typeof queries> = {
-  container: Element
+  container: JSX.Element

@JoviDeCroock
Copy link
Member

if it compiles with it removed (and finds it globally) that's good for me as well but yeah if we can use JSX.Element could be more appropriate😅

@maxbeatty
Copy link
Contributor Author

actually, I think this should be a global Element to satisfy @testing-library/dom

import { render, fireEvent } from '@testing-library/preact';

// container is type Element
const { container } = render(<ExampleComponent />)

// fireEvent expects element to be Document | **Element** | Window | Node
fireEvent(container, new Event('example')

@JoviDeCroock JoviDeCroock merged commit d6fdcfa into testing-library:master Jun 10, 2022
@maxbeatty maxbeatty deleted the fix-preact-type branch June 10, 2022 19:01
@github-actions
Copy link

🎉 This PR is included in version 3.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 this pull request may close these issues.

2 participants