Open AlexReff opened 4 years ago
How about trying to use preact-redux
?
https://github.com/developit/preact-redux
If you're using Preact X (preact@10+), please use the official react-redux library.
Update: it looks as though the core issue might be the type definition of @types/react-redux
's connect
function.
I have not encountered any actual functional bugs outside of this type 'mismatch'
See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/19989
Workarounds:
If you still need other typings for react-redux, just cast as any
wherever needed.
Otherwise,
A) set noImplicitAny
to false
in your tsconfig.json
or
B) create a declarations.d.ts
file with the line declare module "react-redux";
in it, and remove @types/react-redux
entirely.
How about trying to use preact/compat
?
I don't believe there is a connect
function exported in preact/compat
- and using Component
from preact/compat
doesn't change this outcome. I think the issue lies with @types/react-redux
and not with preact itself.
Have you tried aliasing react to preact in the typescript config as well?
Can confirm that @ForsakenHarmony's suggestion works. Your tsconfig should look a little something like this:
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"react": ["node_modules/preact/compat"],
"react-dom": ["node_modules/preact/compat"]
}
}
}
import * as Preact from 'https://unpkg.com/preact?module'
import htm from 'https://unpkg.com/htm?module'
const html = htm.bind(Preact.createElement)
import * as reactRedux from 'https://unpkg.com/react-redux?module'
Is something like this possible? (no typescript, no rollup, etc.)
After setting
noImplicitAny: true
in my project, I realized I was missing the type declarations forreact-redux
. After runningnpm i -D @types/react-redux
, I now get the following error on all of my components that use react-redux'sconnect
Shortened example:
I've googled this as much as I can and have not found any answers. I don't see
$$typeof
anywhere in Preact's index.d.ts file.My tsconfig.json is: