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

Router typings incompatible with class components #35

Closed
foxt opened this issue Aug 22, 2024 · 2 comments · Fixed by preactjs/preact#4479
Closed

Router typings incompatible with class components #35

foxt opened this issue Aug 22, 2024 · 2 comments · Fixed by preactjs/preact#4479

Comments

@foxt
Copy link

foxt commented Aug 22, 2024

<Router>
    {/* Type 'typeof ClassComponent' is not assignable to type 'AnyComponent<{ path: string; component: typeof ClassComponent; }> & (typeof ClassComponent | undefined)'. */}
    <Route path="/class" component={ClassComponent} />
    {/* works ok */}
    <Route path="/fc" component={FunctionComponent} />
</Router>

It works at runtime, but the typing has an error.

@rschristian
Copy link
Member

rschristian commented Aug 22, 2024

I'm not entirely sure that's an issue here at the moment -- I thought AnyComponent (from preact itself) was meant to include class components.

Will need to double check.

Edit: have you explicitly typed that class component?

@rschristian
Copy link
Member

rschristian commented Aug 22, 2024

Found the issue, but I think this should be corrected upstream. If you're willing to patch in the meantime (patch-package or pnpm patch are great for this sort of thing), you can do this:

 // node_modules/preact/src/index.d.ts
 export type AnyComponent<P = {}, S = {}> =
     | FunctionComponent<P>
-    | Component<P, S>;
+    | ComponentConstructor<P, S>;

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

Successfully merging a pull request may close this issue.

2 participants