From d42230443f11279028f932fd6e2940cc02e3dd77 Mon Sep 17 00:00:00 2001 From: unional Date: Mon, 19 Jan 2026 17:49:15 -0800 Subject: [PATCH] fix: improve higher order type inference for WritableDraft --- __tests__/produce.ts | 12 ++++++++++++ src/types/types-external.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/__tests__/produce.ts b/__tests__/produce.ts index c3913873..a7667b13 100644 --- a/__tests__/produce.ts +++ b/__tests__/produce.ts @@ -758,3 +758,15 @@ it("allows for mixed property value types", () => { } }) }) + +it("allows higher order type inference", () => { + function _test() { + type S = {prop: A | undefined} + produce( + draft => { + draft.prop = undefined + }, + {prop: undefined} as S + ) + } +}) diff --git a/src/types/types-external.ts b/src/types/types-external.ts index d3e7df2c..16db28a8 100644 --- a/src/types/types-external.ts +++ b/src/types/types-external.ts @@ -37,7 +37,7 @@ export type WritableDraft = T extends any[] : WritableNonArrayDraft type WritableNonArrayDraft = { - -readonly [K in keyof T]: T[K] extends infer V + -readonly [K in keyof T]: {_: T[K]} extends {_: infer V} ? V extends object ? Draft : V