Skip to content

fix: mark in-bounds indexed reads non-null for noUncheckedIndexedAccess - #1317

Open
cpruijsen wants to merge 1 commit into
immerjs:mainfrom
cpruijsen:fix/issue-1143-fc458e21
Open

cpruijsen wants to merge 1 commit into
immerjs:mainfrom
cpruijsen:fix/issue-1143-fc458e21

Conversation

@cpruijsen

Copy link
Copy Markdown

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.ts adds a compiler regression test. The test uses skipLibCheck to exclude dependency declaration diagnostics.

The regression test fails without the assertions and passes with them.

Fixes #1143.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI Build issue patch - 'patch' is possibly 'undefined'.

1 participant