Repository navigation
Conversation
Consumers that compile the shipped src/ directory with noUncheckedIndexedAccess (for example, builds that transpile node_modules) fail on four indexed reads, starting with `'patch' is possibly 'undefined'` in applyPatches. The indices are bounded by the surrounding loop, the descriptor keys come from Reflect.ownKeys on the same object, and the last path element is present for every patch Immer generates, because the only empty path is a root replace, which applyPatches handles earlier. Assert these reads non-null with `!`, as the codebase already does elsewhere, rather than add runtime guards. Emitted JS is unchanged. Fixes immerjs#1143
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four non-null assertions let Immer's shipped source compile with
noUncheckedIndexedAccess. The assertions do not change emitted JavaScript or behavior for caller-supplied patches.The reads occur in the patch scan, patch path resolution, patch application, and strict shallow copy.
__tests__/type-external.tsadds a compiler regression test. The test usesskipLibCheckto exclude dependency declaration diagnostics.The regression test fails without the assertions and passes with them.
Fixes #1143.