The return type of the produce method will have an additional undefined

オープン
#1,003 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
tooling

調査の方向性

リンクされた CodeSandbox の TypeScript 例から始め、特に src/index.ts とその produce 呼び出しを確認して、報告されている推論された戻り値の型を再現します。9.x バージョンについて示されている期待値と動作を比較します。例の型チェックで、返される Record 型に undefined が追加されなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

question

🙋‍♂ Question

A clear and concise description of what the question is. In general we recommend to use Stack Overflow for questions. Questions typically are processed with less priority.

import { produce } from 'immer';

const func = produce((state: Record<string, string> = {}): Record<string, string> => {
  return state;
});

In the above code, I expect the type of the func to be Record<string, string>, but the actual type check returns Record<string, string> | undefined, how can I avoid the undefined?

image

This problem only occurs in 9.x versions

Link to repro

https://codesandbox.io/s/immer-sandbox-forked-n1okz2?file=/src/index.ts

Environment

We only accept questions against the latest Immer version.

  • Immer version:
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
主要言語
JavaScript
スター
29k
フォーク
905
平均マージ
3日 16時間
マージ済み PR(30日)
22

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

immerjs/immer のほかの issue

immerjs/immer の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。