From aadfd74632ae070848ba4f439b8660bee116011a Mon Sep 17 00:00:00 2001 From: mixelburg Date: Wed, 13 May 2026 22:11:44 +0000 Subject: [PATCH] fix: add optional chaining to patch access in applyPatches for noUncheckedIndexAccess compatibility When TypeScript projects use , array indexing returns . The variable from can be even though the loop bounds are correct, causing a type error: 'patch' is possibly 'undefined' This adds optional chaining (, ) to resolve the type error without changing runtime behavior, since the loop bounds already guarantee the value is defined. Fixes #1143 --- src/core/immerClass.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/immerClass.ts b/src/core/immerClass.ts index 2922f612..c06e29e0 100644 --- a/src/core/immerClass.ts +++ b/src/core/immerClass.ts @@ -208,7 +208,7 @@ export class Immer implements ProducersFns { let i: number for (i = patches.length - 1; i >= 0; i--) { const patch = patches[i] - if (patch.path.length === 0 && patch.op === "replace") { + if (patch?.path.length === 0 && patch?.op === "replace") { base = patch.value break }