Have you considered using Zod
for creating static types?
#567
-
Are you guys aware of Zod or libraries like it to make typescript actually typesafe at runtime not just compiletime? The general idea is you create schemas containing rules and route your logic through zod helpers which not only give you errors where you expect, but automatically generates types for you.
So for example, viem often uses the Similarly the clients would be massively simplified by not having the heavily inferred types supported by reams of type helpers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We are familiar! viem's type inference is powered by our ABIType and it exports Zod schemas for the core ABI types. In key areas, we already validate requests, transactions, etc. at runtime. It's unlikely that we would add extensive additional runtime validation without a specific reason since it will slow things down (Zod isn't very fast compared to other runtime validators) and most folks use viem with TypeScript anyway. –
Say more. Is it cumbersome to assert
Agree that they would be simplified, but we would trade that for worse developer experience (e.g. no more type inference for ABI function/event names, arguments, EIP-721 typed data, etc.) |
Beta Was this translation helpful? Give feedback.
We are familiar! viem's type inference is powered by our ABIType and it exports Zod schemas for the core ABI types.
In key areas, we already validate requests, transactions, etc. at runtime. It's unlikely that we would add extensive additional runtime validation without a specific reason since it will slow things down (Zod isn't very fast compared to other runtime validators) and most folks use viem with TypeScript anyway.
–
Say more. Is it cumbersome to assert
string
s to`0x${string}`
or something else? You can configure the internal types to use whate…