Comments (8)
from abitype.
This is intended behavior. This comes down to the Abi
type using the union of literals "pure" | "view" | "nonpayable" | "payable"
and while zod does the same at runtime, at the typelevel it infers that as a string
type and not their literal values and string extends "anyliteralvalue"
is false so you get that type error when trying to assign that type to the type return from the zod schema parse
from abitype.
The biggest problem is that it makes the Zod extension very difficult to use with abitype itself and viem by extension. I have to make horrible conversions like:
import { Abi } from 'abitype';
import { Abi as AbiSchema } from 'abitype/zod';
const result: Abi = AbiSchema.parse([]) as unknown as Abi;
from abitype.
But why are you assign the ABI to the zod schema parsed? The zod type should be assignable to function were the args expect the Abi
type. Here is an example https://tsplay.dev/w2vD9w
from abitype.
My goal is to build a platform where users can submit ABIs via a form. To verify that the submitted data is a valid ABI, I am using import { Abi as AbiSchema } from 'abitype/zod';
to check if the ABI is valid. If the ABI is valid, I will then use viem to interact with the contracts.
import { Abi } from 'abitype';
import { Abi as AbiSchema } from 'abitype/zod';
const validAbi: Abi = AbiSchema.parse(maybeNotAbi); // not assignable to Abi
To sum up, since the AbiSchema is provided by abitype/zod
, I would expect a parsed zod Abi to be assignable to abitype
's Abi
.
from abitype.
You can still do this without having to cast the parsed zod abi to Abi
.
Take the example above. Its using viem's getContract
function with the zod parsed abi. There is no need here to perform manual casting as this will also works.
Viem docs
However i believed i have found the problem and it should be fixed with #192
from abitype.
Thanks a lot for pointing this to me. While I fully agree that the provided code works, this issue was more about the fact that the Zod schema was not working with the abitype Abi type. However, since there full compatibility with viem, I would consider this issue as "nice-to-have".
I just checked your PR #192 and it looks like that it fixes the issue!
from abitype.
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest ABIType version. If you have any other comments you can create a new discussion.
from abitype.
Related Issues (15)
- bug: type inference won't work when `constructor` has no `stateMutability` property HOT 7
- bug: uint and uint256 parsed different in EIP-712 Typed Data event signatures HOT 5
- test issue ci workflow HOT 1
- bug: parseAbi throws type error HOT 9
- Error when build in Nextjs 12.1.6 HOT 6
- Identifiers with `$` are not recognized HOT 2
- TS build error: instantiation is excessively deep HOT 10
- Extra space in formatAbi return type HOT 4
- `FormatAbiParameter` infers incorrect string on nested unnamed `components` HOT 1
- Compilation issue with TypeScript 5.2.2 HOT 9
- Unable to resolve "abitype/zod" in Expo React Native HOT 3
- Conflict with Typescript version HOT 2
- bug: tuple[] generated type is incorrect? HOT 3
- bug: bytes32 type is too strict HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abitype.