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

make type NamedSet compatible with type SetState #441

Merged
merged 1 commit into from
Jun 20, 2021

Conversation

zgid123
Copy link
Contributor

@zgid123 zgid123 commented Jun 18, 2021

According to #434, we are having issue with typescript when combining devtool with persist middleware.

The main issue is because NamedSet and SetState are not compatible, so I think we can temporary make them compatible.

I already added some codes to test the type for middleware use case only. And also add immer as devDependency for testing (not sure this is a way, I will remove if it's not suitable).

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 18, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ad16a4e:

Sandbox Source
React Configuration
React Typescript Configuration

K3 extends keyof T = K2,
K4 extends keyof T = K3
>(
partial: PartialState<T, K1, K2, K3, K4>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good.

@zgid123
Copy link
Contributor Author

zgid123 commented Jun 19, 2021

I updated the test file. Not sure if we can combine devtool, persist and immer or not. Can anyone helps to provide a usage?

I think something like this right?

const createStoreWithImmer = <T extends State>(
    createState: TImmerConfig<T>,
    prefix = 'prefix',
    persistName = 'persist'
  ): UseStore<T> & ISelectors<T> => {
    return createSelectorHooks(
      create(
        devtools(persist(immer(createState), { name: persistName }), prefix)
      )
    )
  }

@dai-shi
Copy link
Member

dai-shi commented Jun 19, 2021

Is this related with #216?
#212, #331, #411 are also in the same domain?

I know typing with middleware has been not ideal and, v3.5.* kind of revealed it. #428 is another effort.

I appreciate for your work and hope anyone can jump in.

@dai-shi
Copy link
Member

dai-shi commented Jun 20, 2021

@TkDodo Do you think OK to merge this? Can review?

@dai-shi dai-shi requested a review from TkDodo June 20, 2021 11:26
@zgid123
Copy link
Contributor Author

zgid123 commented Jun 20, 2021

I tried to solve other issues, but still no luck. Will update it if I can solve any issue

@dai-shi
Copy link
Member

dai-shi commented Jun 20, 2021

@zgid123 This PR itself is ready for review and merge, right?

@zgid123
Copy link
Contributor Author

zgid123 commented Jun 20, 2021

Yup, this is for #434

@dai-shi dai-shi linked an issue Jun 20, 2021 that may be closed by this pull request
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, everyone.

@dai-shi dai-shi merged commit 836aeae into pmndrs:master Jun 20, 2021
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 this pull request may close these issues.

[v3.5.2] Type error when using devtools and persist in TypeScript
3 participants