From 1ce88da600a5a209d78e6a4fe2741357f6910d96 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 30 Oct 2023 07:58:35 +0100 Subject: [PATCH] Enable noUncheckedIndexedAccess in tsconfig.json --- index.ts | 13 ++++--------- tsconfig.json | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/index.ts b/index.ts index 6f86ce5..638958c 100644 --- a/index.ts +++ b/index.ts @@ -312,15 +312,13 @@ export function fieldsAuto( return objectResult; } const object = objectResult.value; - const keys = Object.keys(mapping); const knownFields = new Set(); const result: Record = {}; - for (const key of keys) { + for (const [key, fieldOrCodec] of Object.entries(mapping)) { if (key === "__proto__") { continue; } - const fieldOrCodec = mapping[key]; const field_: Field = "codec" in fieldOrCodec ? fieldOrCodec : { codec: fieldOrCodec }; const { @@ -383,11 +381,10 @@ export function fieldsAuto( }, encoder: (object) => { const result: Record = {}; - for (const key of Object.keys(mapping)) { + for (const [key, fieldOrCodec] of Object.entries(mapping)) { if (key === "__proto__") { continue; } - const fieldOrCodec = mapping[key]; const field_: Field = "codec" in fieldOrCodec ? fieldOrCodec : { codec: fieldOrCodec }; const { @@ -658,8 +655,7 @@ export function tuple>>( }; } const result = []; - for (let index = 0; index < arr.length; index++) { - const codec = codecs[index]; + for (const [index, codec] of codecs.entries()) { const decoderResult = codec.decoder(arr[index]); switch (decoderResult.tag) { case "DecoderError": @@ -679,8 +675,7 @@ export function tuple>>( }, encoder: (value) => { const result = []; - for (let index = 0; index < codecs.length; index++) { - const codec = codecs[index]; + for (const [index, codec] of codecs.entries()) { result.push(codec.encoder(value[index])); } return result as InferEncodedTuple; diff --git a/tsconfig.json b/tsconfig.json index ab33037..ef27776 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "noFallthroughCasesInSwitch": true, "noImplicitOverride": true, "noImplicitReturns": true, + "noUncheckedIndexedAccess": true, "skipLibCheck": true, "strict": true, "exactOptionalPropertyTypes": true,