Unable to pass generic to produce for dynamic typing

未关闭
#1,130 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
typescript
领域
api

调研方向

从链接的 CodeSandbox 复现开始,比较 issue 中展示的泛型调用和具体调用。阅读 Immer 中 produce 及其相关 draft 类型的 TypeScript 声明。完成标准是确定所报告的泛型调用是否受支持,或记录所需的用法;如果需要修改库,则提供一个针对性的复现或测试。

由索引模型根据 Issue 内容生成。

描述

question

🙋‍♂ 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"
主要语言
JavaScript
星标
29k
派生
905
平均合并
3 天 16 小时
30 天内合并 PR
22

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

immerjs/immer 的其他 Issue

查看 immerjs/immer 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。