wevm / abitype

Strict TypeScript types for Ethereum ABIs
https://abitype.dev
MIT License
480 stars 45 forks source link

fix: flatten nested arrays in parseAbiParameters #232

Closed xenoliss closed 7 months ago

xenoliss commented 8 months ago

Description

Hopefully fix https://github.com/wevm/abitype/issues/231

Additional Information

Introduce a DeepFlatten and use it in ParseAbiParameters instead of assuming that Filter<Mapped, never> has always only one element.

NOTE: I had to update parseAbiParameters to return abiParameters as unknown as ParseAbiParameters<TParams> for the compiler to be happy but waiting for feedback.

Before submitting this issue, please make sure you do the following.


PR-Codex overview

This PR focuses on fixing type detection in ParseAbiParameters when using an array.

Detailed summary

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

changeset-bot[bot] commented 8 months ago

⚠️ No Changeset found

Latest commit: 9a03cf1a7fa80e4d8b1d34434d382ed64451bd68

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abitype ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 14, 2024 7:38am
Raiden1411 commented 8 months ago

Can you add a test based on #231? You can use the provided playground as the base for the test. That way if there is a unforseen regression that test catches it.

xenoliss commented 7 months ago

Sure! I noticed the type tests are failing. I need to fix that as well when I find time. Any help/guidance is welcomed

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.85%. Comparing base (6b2979f) to head (9ad4c80). Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #232 +/- ## ========================================== + Coverage 99.83% 99.85% +0.01% ========================================== Files 26 26 Lines 6082 6105 +23 Branches 195 195 ========================================== + Hits 6072 6096 +24 Misses 8 8 + Partials 2 1 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Raiden1411 commented 7 months ago

@xenoliss since depth flatten returns a arraylist now you need to check if it's length is 0 instead of checking if the list member is undefined which was the previous implementation so that it shows as never for the parameters.

Something like this should work. But feel free to take any other approach

? Filter<Mapped, never> extends readonly [...infer Content]
  ? Content['length'] extends 0
    ? never
    : DeepFlatten<Content>
  : never
: never
xenoliss commented 7 months ago

Hey thank you @Raiden1411, I added your fix and it seems to work fine. I also added the playground test. Let me know how that looks to you.

Raiden1411 commented 7 months ago

I think that the only thing that is missing is the changeset otherwise it looks good

xenoliss commented 7 months ago

I added the changeset @Raiden1411