Skip to content

Commit

Permalink
Type update for encjodeJSON function
Browse files Browse the repository at this point in the history
  • Loading branch information
ioay committed Apr 4, 2024
1 parent c545342 commit 597b0f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dapp/src/store/devTools.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { encodeJSON } from "#/utils"

function devToolsSanitizer<T>(input: T) {
function devToolsSanitizer(input: unknown): unknown {
switch (typeof input) {
// We can make use of encodeJSON instead of recursively looping through
// the input
case "bigint":
case "object":
// We only need to sanitize bigints and objects
// that may or may not contain them.
return JSON.parse(encodeJSON(input)) as T
return JSON.parse(encodeJSON(input))
default:
return input
}
Expand Down
5 changes: 2 additions & 3 deletions dapp/src/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
*
* @param input an object, array, or primitive to encode as JSON
*/
export function encodeJSON(input: unknown): string {
return JSON.stringify(input, (_, value): object | null => {
export function encodeJSON(input: unknown) {
return JSON.stringify(input, (_, value: unknown) => {
if (typeof value === "bigint") {
return { B_I_G_I_N_T: value.toString() }
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value
})
}

0 comments on commit 597b0f8

Please sign in to comment.