microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

TypeScript React: incorrect children props #193

Open ChromeQ opened 2 years ago

ChromeQ commented 2 years ago

192 fixes TS errors since DefinitelyTyped updated react types to v18.

Pabliomen commented 2 years ago

@ChromeQ is there a way we can use your fork as a temporary solution?

I've tried adding it to my packages with yarn add ChromeQ/redux-dynamic-modules but it looks like it can't find it.

mrluscus commented 1 year ago

Based on this PR: https://github.com/microsoft/redux-dynamic-modules/pull/192

You can extend 'IDynamicModuleLoaderProps' interface in your *.d.ts (like in global.d.ts). Just add:

declare module 'redux-dynamic-modules-react' {
  export interface IDynamicModuleLoaderProps {
    /** Explicitly name children as a prop to work with @types/react@18 */
    children: React.ReactNode;
  }
}
davoam commented 6 months ago

Thanks @mrluscus ! I just want to add that in our case without importing redux-dynamic-modules-react other error appeared. It was complaining that DynamicModuleLoader is not exported.

Our solution was:

  1. Create file redux-dynamic-modules-react.d.ts (optional, you may add lines below to global.d.ts)
  2. Add the following content
    
    import * as reduxDynamicModulesReact from 'redux-dynamic-modules-react';

declare module 'redux-dynamic-modules-react' { export interface IDynamicModuleLoaderProps { children: React.ReactNode; } }