From d824cd4fa6692ca1e04173b892278b79587a88fb Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Tue, 19 Nov 2024 06:36:23 +0700 Subject: [PATCH] CODEBASE: Add comments to Generic_fromJSON (#1776) --- src/utils/JSONReviver.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/JSONReviver.ts b/src/utils/JSONReviver.ts index b78fe2d54..f278131af 100644 --- a/src/utils/JSONReviver.ts +++ b/src/utils/JSONReviver.ts @@ -102,6 +102,7 @@ export function Generic_fromJSON>( for (const key of keys as string[]) { const val = data[key]; if (val !== undefined) { + // This is an unsafe assignment. We may load data with wrong types at runtime. // @ts-expect-error -- TypeScript won't allow this action: Type 'T' is generic and can only be indexed for reading. obj[key] = val; } @@ -109,6 +110,9 @@ export function Generic_fromJSON>( return obj; } // No keys provided: load every key in data - for (const [key, val] of Object.entries(data) as [keyof T, T[keyof T]][]) obj[key] = val; + for (const [key, val] of Object.entries(data) as [keyof T, T[keyof T]][]) { + // This is an unsafe assignment. We may load data with wrong types at runtime. + obj[key] = val; + } return obj; }