@tevm/actions
Version:
A typesafe library for writing forge scripts in typescript
31 lines (27 loc) • 1.02 kB
text/typescript
// TODO this is duplicated in tevm/utils
import type { Hex } from '@tevm/utils'
export type JsonSerializable =
| bigint
| string
| number
| boolean
| null
| JsonSerializableArray
| JsonSerializableObject
| JsonSerializableSet
| (Error & { code: number | string })
export type JsonSerializableArray = ReadonlyArray<JsonSerializable>
export type JsonSerializableObject = { [key: string]: JsonSerializable }
export type JsonSerializableSet<T extends bigint | string | number | boolean = bigint | string | number | boolean> =
Set<T>
export type BigIntToHex<T> = T extends bigint ? Hex : T
export type SetToHex<T> = T extends Set<any> ? Hex : T
export type SerializeToJson<T> = T extends Error & { code: infer TCode }
? { code: TCode; message: T['message'] }
: T extends JsonSerializableSet<infer S>
? ReadonlyArray<S>
: T extends JsonSerializableObject
? { [P in keyof T]: SerializeToJson<T[P]> }
: T extends JsonSerializableArray
? SerializeToJson<T[number]>[]
: BigIntToHex<SetToHex<T>>