immerjs / immerjs/immer

Unable to pass generic to produce for dynamic typing

Open
#1,130 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
29k
Forks
881
PR merge metrics
No merged PRs in 30d

Description

🙋‍♂ Question

I am unable to pass generic parameter type to my produce function in order to propagate that generic to type of draft itself like so:
SearchContextProvider:
Screenshot 2024-06-19 at 10 59 49 PM
Reducer:
Screenshot 2024-06-19 at 11 00 43 PM
State for the draft to be applied:
Screenshot 2024-06-19 at 11 01 21 PM
Error:
Screenshot 2024-06-19 at 11 01 42 PM

This only occures with generic, if I use concrete type I won't get such error (namely If I replace generic with ResultDummy - error vanishes.

How do I go about it since this Provider supposed to be used in different part of the code and should receive different type depends on part of the code where it is used. Thank you!

Here is playground where I reproduced the issue:
https://codesandbox.io/s/produce-with-generic-vchkj4

Environment

We only accept questions against the latest Immer version.

  • Immer version: "^10.1.1"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and compare the generic and concrete calls shown in the issue. Read Immer's TypeScript declarations for produce and its related draft types. Done means determining whether the reported generic call is supported or documenting the required usage, with a focused reproduction or test if a library change is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.