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

@types/react 18.0.0 not compatible with Easy Peasy #741

Closed
w3bdesign opened this issue Apr 8, 2022 · 8 comments
Closed

@types/react 18.0.0 not compatible with Easy Peasy #741

w3bdesign opened this issue Apr 8, 2022 · 8 comments
Milestone

Comments

@w3bdesign
Copy link
Contributor

w3bdesign commented Apr 8, 2022

I am getting a Typescript error if I upgrade @types/react to version 18.0.0 and use Easy Peasy:

Type error: No overload matches this call.

Overload 1 of 2, '(props: { store: Store<StoreModel, EasyPeasyConfig<undefined, {}>>; } | Readonly<{ store: Store<StoreModel, EasyPeasyConfig<undefined, {}>>; }>): StoreProvider<...>', gave the following error.

Overload 2 of 2, '(props: { store: Store<StoreModel, EasyPeasyConfig<undefined, {}>>; }, context: any): StoreProvider<StoreModel>', gave the following error.

     <StoreProvider store={store}>
     <Component {...pageProps} />
      </StoreProvider>
@wclear
Copy link

wclear commented Apr 27, 2022

Here is an example of how to temporarily workaround this issue until the fix is published:

...
import { StoreProvider } from 'easy-peasy';

const StoreProviderOverride = StoreProvider as any;

function WebAppContainer() {
	return (
		<StoreProviderOverride store={webAppStore}>
			...
		</StoreProviderOverride>
	)
}

@w3bdesign
Copy link
Contributor Author

Here is an example of how to temporarily workaround this issue until the fix is published:

...
import { StoreProvider } from 'easy-peasy';

const StoreProviderOverride = StoreProvider as any;

function WebAppContainer() {
	return (
		<StoreProviderOverride store={webAppStore}>
			...
		</StoreProviderOverride>
	)
}

@wclear

Wouldn't this disable Typescript if you cast the provider as any?

@asiraky
Copy link

asiraky commented May 25, 2022

I believe the more correct way to augment the type is to do the following:

type Props = StoreProvider["props"] & { children: React.ReactNode }

const StoreProviderCasted = StoreProvider as unknown as React.ComponentType<Props>

function WebAppContainer() {
    return (
        <StoreProviderCasted store={webAppStore}>
            ...
        </StoreProviderCasted>
    )
}

This will keep all the strong typing and add the children prop back to the type.

@mighdoll
Copy link
Contributor

For convenience until a new rev is published, I pushed a fork to github with @magicdawn's fix. You can use the fork from package.json like this:

"easy-peasy": "mighdoll/patched-peasy#fix-explicit-children",

@liamdefty
Copy link

Just noting that from my findings another change is needed for react 18 support

In React 18 the FunctionalComponent interface has changed. The PropsWithChildren type is omitted which means a similar issue for createContextStore. I think all we'd need to do is wrap the Provider typing with PropsWithChildren

https://github.com/ctrlplusb/easy-peasy/blob/master/index.d.ts#L1093-L1096

Provider: React.FC<PropsWithChildren{
    runtimeModel?: RuntimeModel;
    injections?: Injections | ((previousInjections: Injections) => Injections);
  }>>;

@azuken
Copy link

azuken commented Jul 21, 2022

We have also an error when trying to use Store Provider as JSX element, created with createContextStore function.

Type error: Type '{ children: ReactNode; }' has no properties in common with type 'IntrinsicAttributes & { runtimeModel?: { my: MyModel }; injections?: {} | ((previousInjections: {}) => {}); }'.

  16 |   }
  17 | 
> 18 |   return <MyContextStore.Provider>{props.children}</MyContextStore.Provider>;
     |           ^
  19 | };
  20 | 
  21 | export { MyProvider, MyContextStore };

@ctrlplusb
Copy link
Owner

FYI please see;

#740 (comment)

@ctrlplusb ctrlplusb added this to the v5.1.0 milestone Sep 16, 2022
@ctrlplusb ctrlplusb unpinned this issue Sep 16, 2022
@ctrlplusb
Copy link
Owner

Fixed in v5.1.0 🎉

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

Successfully merging a pull request may close this issue.

7 participants