wagmi: Getting strange typescript errors on usePrepareContractWrite after updating to 1.0.2

Is there an existing issue for this?

  • I have searched the existing issues

Package Version

1.0.2

Current Behavior

I have the following method:

const { config, error, isError } = usePrepareContractWrite({
  abi: contract?.options?.jsonInterface ?? [],
  address: contract?.options?.address as any,
  functionName: method,
  overrides: {
    from,
    value: value ? BigNumber.from(value) : null,
  },
  args,
})

But getting typescript errors on the abi, address, functionName and overrides as such

  • Type ‘AbiItem[]’ is not assignable to type ‘never’
  • Type ‘any’ is not assignable to type ‘never’
  • Type ‘string’ is not assignable to type ‘never’
  • Type ‘{ from: 0x${string}; value: BigNumber; }’ is not assignable to type ‘never’

Have a similar problem with publicClient.getTransactionReceipt(). Inspecting the property:

(property) getTransactionReceipt: (args: GetTransactionReceiptParameters) => Promise<never>

The never at the end there, what is that? I can solve typescript errors by forcing the TransactionReceipt type as such:

const receipt: TransactionReceipt = await publicClient.getTransactionReceipt({ hash: data.hash })

image

Expected Behavior

I did not have any typescript errors here with v. 0.12.12

Steps To Reproduce

Using usePrepareContractWrite in vsCode.

Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)

No response

Anything else?

Don’t know if it’s related but I can’t add dynamic arguments to write or writeAsync from useContractWrite. Referring to https://wagmi.sh/react/hooks/useContractWrite you are supposed to be able to pass dynamic arguments. But typescript says 0 arguments are expected for the write function so I’m stuck and cannot use it.

write({
  args: [69],
  from: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  value: parseEther('0.01'),
})

image

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 24 (7 by maintainers)

Most upvoted comments

I’ve narrowed it down to setting strict: true in tsconfig.json which resolves both issues for me (never and () => void types)

On it 👍 will drop an example repo later today!

@paintoshi - we are in the same boat, but working on it 💪

Setting strict true worked for me. We build in an NX mono repo, so I had to update the tsconfig.base and the application’s tsconfig to strict true.

It’s worth a call out that this setting need is called out in the docs: https://next.wagmi.sh/react/typescript

But not in the migration guide.