-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[typescript] React.ReactElement type is not compatible with Preact and prevents interoperability with React #2748
Comments
From what I can tell, this is being caused by this file - https://github.com/preactjs/enzyme-adapter-preact-pure/blob/master/index.d.ts A quick fix would be to make the "nodeName", "attributes", and "children" optional. Looking for a more legit fix, but thanks for the workaround! |
FYI: We don't have |
@marvinhagemeister I should have mentioned, this is happening with Preact To reproduce (with preact-cli 3.0.3)
You can also use OPs method for reproducing, this was just the way I ran into this bug. The issue is due to the fact that the |
cc @robertknight who maintains our enzyme adapter |
@marvinhagemeister @robertknight Bump. This is still causing issues. |
The types defined in `index.d.ts` are only for use by the package's internal code and tests. There is nothing there that should be published. See preactjs/preact#2748
@colin-ggd - Would you be able to help me test preactjs/enzyme-adapter-preact-pure#124? It looks to me like all of the type definitions in Edit: Nevermind - it is not ready yet. I rushed this. Some other changes are required. |
Move Preact 8 VNode extensions from `index.d.ts` to `internal.d.ts` to avoid shipping them with the package and causing type checking errors for Preact 10 users. See preactjs/preact#2748
Remove Preact 8 VNode extensions from `index.d.ts` as these cause type checking errors for Preact 10 users. See preactjs/preact#2748
@robertknight I've also experienced this issue today, but since I don't use enzyme I just completely removed it from the preact typescript project. I wonder why the typescript template defaults to enzyme for unit testing components? |
All of the templates should be using enzyme for unit testing, not just TS. Is there something else you think it should be defaulting to? Enzyme is quite a nice test framework and I certainly prefer it to the rest. |
@rschristian I'd opt for Testing Library, as it's the first listed in the docs. |
@simonv3 Gotcha, makes sense. Maybe at some point the templates will be converted then. |
This may not be Preact's issue. I'm working on a React project and I'm getting a very similar error. Here's a minimal example: const Foo: React.FC = () => <p></p>
function Bar() {
return <Foo /> /* Type error! */
} This gives the following TS error:
No idea what's causing this. I'm using React 17. Would be great to have a workaround. |
@gilbert that is it related to Preact. Can you file that issue in the React repo instead? This issue here is about interoperability between React and Preact typings and it sounds like you're not using Preact in the first place. |
@marvinhagemeister Right. I posted not to get help, but to point out how |
I'm still getting this with @types/react@16 and @types/react@17, [email protected], [email protected]. Is there any other workaround apart from the original poster? That doesn't work for me. |
I had the similar issue in which I'm using a react component in which one of the props allow for a React.ReactElement in which a VNode isn't matching.
I was pretty sure that having the following in webpack would do the same (but maybe that wasn't working in my setup):
|
May I suggest that this issue is marked as a documentation issue by adding @Svampen fix to the Typescript Configuration section in the docs. @Svampen suggests above adding the following to
The paths are relative to the You have no control over what and how other imported packages and their dependencies reference and cause Whichever way it gets loaded, once it is, you are in trouble. By equating the paths to |
This has been added to the dos in preactjs/preact-www#850 thank you @Satyam |
There is a type mismatch between
React.ReactElement
andpreact.VNode
that prevents usage of typescript/react code with typescript/preact.While the code below compiles and works without an issue, Typescript typechecking fails.
Reproduction
This results in the following typescript error:
Typescript config:
Deps:
Tested with Typescript:
4.0.2
/3.9.7
Expected Behavior
Preact should be able to interlope with components that use typescript and
@types/react
. There a lot of components like that.Workaround
This is a very dumb workaround, but it works:
The text was updated successfully, but these errors were encountered: