From 9cc7190589931745f712caa48172712efbb4771e Mon Sep 17 00:00:00 2001 From: Khurram Jalil <114917595+KhurramJalil@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:29:00 +0500 Subject: [PATCH] improv(commons): add `number` key type to `JSONObject` type The change introduced in this PR allows to narrow the type of JSON objects using numbers as key. JSON allows only string types as keys, however JavaScript coerces the value to a string even when a number is passed. --- packages/commons/src/types/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commons/src/types/utils.ts b/packages/commons/src/types/utils.ts index 64a322020d..7da5fd17ab 100644 --- a/packages/commons/src/types/utils.ts +++ b/packages/commons/src/types/utils.ts @@ -53,7 +53,7 @@ export { isRecord, isString, isTruthy, isNullOrUndefined }; type JSONPrimitive = string | number | boolean | null | undefined; type JSONValue = JSONPrimitive | JSONObject | JSONArray; -type JSONObject = { [key: string]: JSONValue }; +type JSONObject = { [key: number | string]: JSONValue }; type JSONArray = Array; export type { JSONPrimitive, JSONValue, JSONObject, JSONArray };