Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepareEncodeFunctionData drop type safety #2591

Closed
1 task done
SebastienGllmt opened this issue Aug 7, 2024 · 1 comment
Closed
1 task done

prepareEncodeFunctionData drop type safety #2591

SebastienGllmt opened this issue Aug 7, 2024 · 1 comment

Comments

@SebastienGllmt
Copy link

SebastienGllmt commented Aug 7, 2024

Check existing issues

Viem Version

2.18.8

Current Behavior

You can pass incorrect values for args in encodeFunctionData without a type error

Expected Behavior

A type error just like if you use the abi field directly without using prepareEncodeFunctionData

Steps To Reproduce

You can see if I use prepareEncodeFunctionData, there is no type error detected

const constInputData = prepareEncodeFunctionData({
  abi: [
    {
      inputs: [{ internalType: 'string', name: 'input', type: 'string' }],
      name: 'convertedPaimaData',
      outputs: [],
      stateMutability: 'nonpayable',
      type: 'function',
    },
  ],
});

const foo = encodeFunctionData({
  ...constInputData,
  args: [1], // note: wrong data, but no error!
});

However, if I inline the abi directly, it properly detects the error

const foo = encodeFunctionData({
  abi: [
    {
      inputs: [{ internalType: 'string', name: 'input', type: 'string' }],
      name: 'convertedPaimaData',
      outputs: [],
      stateMutability: 'nonpayable',
      type: 'function',
    },
  ],
  args: [1], // error working properly as expected: Type 'number' is not assignable to type 'string'
});

Link to Minimal Reproducible Example

No response

Anything else?

No response

@jxom jxom closed this as completed in a6d087e Aug 7, 2024
Copy link
Contributor

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 Viem version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant