Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions __tests__/type-external.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import {isType, JSONArray, JSONObject, JSONTypes} from "type-plus"
import {Draft} from "../src/types/types-external"
import {createDraft, current, original} from "../src/immer"
import ts from "typescript"

test("source compiles with noUncheckedIndexedAccess (#1143)", () => {
const {config, error} = ts.readConfigFile("tsconfig.json", ts.sys.readFile)
expect(error).toBeUndefined()
const parsed = ts.parseJsonConfigFileContent(config, ts.sys, ".", {
noUncheckedIndexedAccess: true,
skipLibCheck: true
})
const program = ts.createProgram(parsed.fileNames, parsed.options)
expect(
[...parsed.errors, ...ts.getPreEmitDiagnostics(program)].map(diagnostic =>
ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
)
).toEqual([])
})

describe("Draft<T>", () => {
test("can use JSONTypes as T", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/immerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class Immer implements ProducersFns {
// before applying patches
let i: number
for (i = patches.length - 1; i >= 0; i--) {
const patch = patches[i]
const patch = patches[i]!
if (patch.path.length === 0 && patch.op === "replace") {
base = patch.value
break
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function enablePatches() {
function resolvePath(base: any, path: PatchPath): any {
let current = base
for (let i = 0; i < path.length - 1; i++) {
const key = path[i]
const key = path[i]!
current = get(current, key)
if (!isObjectish(current) || current === null) {
throw new Error(`Cannot resolve path at '${path.join("/")}'`)
Expand Down Expand Up @@ -351,7 +351,7 @@ export function enablePatches() {

const type = getArchtype(base)
const value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411
const key = path[path.length - 1]
const key = path[path.length - 1]!
switch (op) {
case REPLACE:
switch (type) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function shallowCopy(base: any, strict: StrictMode) {
let keys = Reflect.ownKeys(descriptors)
for (let i = 0; i < keys.length; i++) {
const key: any = keys[i]
const desc = descriptors[key]
const desc = descriptors[key]!
if (desc[WRITABLE] === false) {
desc[WRITABLE] = true
desc[CONFIGURABLE] = true
Expand Down