Skip to content

Commit

Permalink
improv(commons): add number key type to JSONObject type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KhurramJalil authored Sep 27, 2023
1 parent 58120e3 commit 9cc7190
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/commons/src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSONValue>;

export type { JSONPrimitive, JSONValue, JSONObject, JSONArray };

0 comments on commit 9cc7190

Please sign in to comment.