Replies: 1 comment 1 reply
-
My feeling is that I am going to need to do something like this: const useCustomPrepareContractWrite(config: NewTypeThatSupportsUnions) => {
return usePrepareContractWrite(config)
} This approach seems fine to me, and I could use some type casting internally to make the In my previous attempts to do this, I ended up basically moving the problem on to |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently running into a pretty gnarly TypeScript error when using
usePrepareContractWrite
with a dynamic configuration object passed into the hook. I believe this is only a TypeScript issue, and doesn't create any issues at runtime. Please let me know if there's a better way to do what I'm trying to achieve here.I'm running into issues when writing code similar to this:
In reality, the code I have is more complex than that, but ultimately results in a union type being passed into
usePrepareContractWrite
. Here's an example closer to what I'm actually doing:Both of these examples lead to a variation of the following error:
This error is obviously pretty hard to parse, but in short it's saying that abi 1 has one item, while abi 2 has two. In another case I have seen developing against real ABIs, the error is the same, but reflects the length of each ABI (
Source has 24 element(s) but target requires 113
).My understanding of what's happening is that I am essentially creating a union of two possible objects, something roughly like this:
This type is accurate for what I'm trying to do here — I do want it to be one of two posible object shapes. When this type gets passed into
usePrepareContractWrite
though, I believe internally it's being converted to something like this, which later leads to the nasty type error I'm encountering:This type is no longer quite accurate, and looses some safety since the relationship between
args
,functionName
andabi
has been lost. This type then gets passed intouseContractWrite
, leading to more somewhat cryptic type errors.I'm wondering if there is a way to use
usePrepareContractWrite
, but opt-out of the type-checking for the options object that gets passed in to the hook? I think the types are correct, but don't work in the specific scenario of using a union of config objects. I have tried various versions of passing generic types intousePrepareContractWrite
, but can't ever get it to work with dynamicabi
s.I created this sandbox with a few examples to repro the type errors we have been seeing. Any advice here would be appreciated. Thanks! 😄
Beta Was this translation helpful? Give feedback.
All reactions