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 types for react-dom/client package in compat #3845

Closed
1 task done
WDeenik opened this issue Jan 2, 2023 · 5 comments · Fixed by preactjs/preact-www#1122 or #4345
Closed
1 task done

Missing types for react-dom/client package in compat #3845

WDeenik opened this issue Jan 2, 2023 · 5 comments · Fixed by preactjs/preact-www#1122 or #4345

Comments

@WDeenik
Copy link

WDeenik commented Jan 2, 2023

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
When we switched to Preact using compat, we got the following TS error:

Could not find a declaration file for module 'react-dom/client'. I've looked around but although this module does exist and everything functions like it should, I couldn't find type declarations for it.

I solved it for now by adding a custom declarations file with the proper types, but it would be nice if this is included in Preact itself.

To Reproduce

I can't get preact/compat to work in codesandbox unfortunately. Simplest reproduction steps would be to alias Preact in a simple React 18 TS app.

Expected behavior
I would have expected that there would be types for react-dom/client in preact/compat, where I at most would have to add another entry to the "paths" in my tsconfig.json

@developit
Copy link
Member

I believe right now the recommended workaround is to alias this. In order to support the types for subpath imports, we need to have separate d.ts files - using a module declaration for react-dom/client assumes preact/compat is being aliased everywhere, which isn't always how it is used.

@bluetech
Copy link

I tried the solution given in preactjs/preact-www#1122 but I don't think it solves the actual issue, since compat/client doesn't have a d.ts file, so typescript doesn't know about it even with the alias.

@rschristian
Copy link
Member

Strange, seemed to work just fine in my tests.

Can create a new project with npm init preact, toss in that new path alias, and get working types.

@bluetech
Copy link

I tried it using npm init preact, installing typescript, adding the aliases, and changing index.tsx to use createRoot (imported as import { createRoot } from 'react-dom/client'). Indeed typescript doesn't complain however the createRoot function has type any. Do you see it properly typed?

@rschristian
Copy link
Member

Whoops, indeed.

Oddly, when I go to import either, the types will be sorta inferred (i.e., createRoot: (c: any, o: any) => any), but when I go to use it, it is a bare any (createRoot: any). I must've glanced at this and thought all was good.

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