Skip to content

Conversation

@tmm
Copy link
Member

@tmm tmm commented Jun 2, 2023

Description

Adds support for overload narrowing in examples. For example, supposed I have the following ABI:

const abi = parseAbi([
  'function foo() returns (bool)',
  'function foo(uint) view returns (address)',
  'function foo(address) view returns (uint)',
  'function foo(uint256, address) view returns (address, uint8)',
])

Function foo has multiple overloads. Previously, calling read with foo would return a union for the return type:

const res = read({
  abi,
  functionName: 'foo',
  args: [123n, '0x'],
})
res
// ^? const res: boolean | `0x${string}` | bigint | readonly [`0x${string}`, number]

This PR adds logic to narrow the return type further based on args so it only returns the result for the matched overload:

res
// ^? const res: readonly [`0x${string}`, number]

TODO

Additional Information

  • I read the contributing guide
  • I added documentation related to the changes made.
  • I added or updated tests related to the changes made.

Your ENS/address: awkweb.eth


PR-Codex overview

This PR removes internal barrel exports, reorganizes some imports, and improves type definitions.

Detailed summary

  • Removed internal barrel exports.
  • Reorganized some imports.
  • Improved type definitions.

The following files were skipped due to too many changes: src/test/human-readable.ts, src/abi.ts, src/human-readable/runtime/utils.ts, examples/write.ts, src/human-readable/parseAbiParameter.ts, src/zod/zod.test.ts, src/human-readable/parseAbiParameters.ts, examples/watchEvent.ts, src/index.ts, examples/read.ts, examples/watchEvent.test-d.ts, examples/signTypedData.ts, package.json, examples/reads.ts, examples/reads.test-d.ts, examples/write.test-d.ts, examples/readContract.test-d.ts, examples/types.ts, examples/signTypedData.test-d.ts

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

@changeset-bot
Copy link

changeset-bot bot commented Jun 2, 2023

🦋 Changeset detected

Latest commit: 42346ad

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@commit-lint
Copy link

commit-lint bot commented Jun 2, 2023

Wip

Features

Code Refactoring

Chore

Tests

Contributors

tmm

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

@vercel
Copy link

vercel bot commented Jun 2, 2023

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 Jun 9, 2023 10:43pm

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

Size Change: -2.63 kB (-6%) ✅

Total Size: 44.2 kB

Filename Size Change
dist/cjs/human-readable/errors/index.js 0 B -507 B (removed) 🏆
dist/cjs/human-readable/index.js 0 B -543 B (removed) 🏆
dist/cjs/human-readable/parseAbi.js 348 B +19 B (+6%) 🔍
dist/cjs/human-readable/parseAbiItem.js 439 B +23 B (+6%) 🔍
dist/cjs/human-readable/parseAbiParameter.js 470 B +19 B (+4%)
dist/cjs/human-readable/parseAbiParameters.js 527 B +26 B (+5%) 🔍
dist/cjs/human-readable/runtime/index.js 0 B -356 B (removed) 🏆
dist/cjs/human-readable/runtime/structs.js 1.03 kB +27 B (+3%)
dist/cjs/human-readable/runtime/utils.js 2.13 kB +31 B (+1%)
dist/cjs/human-readable/types/index.js 0 B -125 B (removed) 🏆
dist/cjs/index.js 662 B +102 B (+18%) ⚠️
dist/cjs/test/human-readable.js 3.6 kB +3 B (0%)
dist/cjs/test/index.js 0 B -595 B (removed) 🏆
dist/cjs/zod/index.js 0 B -520 B (removed) 🏆
dist/cjs/zod/zod.js 0 B -1.41 kB (removed) 🏆
dist/esm/human-readable/errors/index.js 0 B -251 B (removed) 🏆
dist/esm/human-readable/index.js 0 B -251 B (removed) 🏆
dist/esm/human-readable/parseAbi.js 267 B +10 B (+4%)
dist/esm/human-readable/parseAbiItem.js 353 B +9 B (+3%)
dist/esm/human-readable/parseAbiParameter.js 383 B +10 B (+3%)
dist/esm/human-readable/parseAbiParameters.js 436 B +8 B (+2%)
dist/esm/human-readable/runtime/index.js 0 B -167 B (removed) 🏆
dist/esm/human-readable/runtime/structs.js 942 B +16 B (+2%)
dist/esm/human-readable/runtime/utils.js 2.03 kB +17 B (+1%)
dist/esm/human-readable/types/index.js 0 B -64 B (removed) 🏆
dist/esm/index.js 316 B +54 B (+21%) 🚨
dist/esm/test/human-readable.js 3.49 kB +4 B (0%)
dist/esm/test/index.js 0 B -296 B (removed) 🏆
dist/esm/zod/index.js 0 B -225 B (removed) 🏆
dist/esm/zod/zod.js 0 B -1.25 kB (removed) 🏆
dist/cjs/test.js 597 B +597 B (new file) 🆕
dist/cjs/zod.js 1.41 kB +1.41 kB (new file) 🆕
dist/esm/test.js 298 B +298 B (new file) 🆕
dist/esm/zod.js 1.25 kB +1.25 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
dist/cjs/abi.js 123 B
dist/cjs/config.js 126 B
dist/cjs/errors.js 577 B
dist/cjs/human-readable/errors/abiItem.js 537 B
dist/cjs/human-readable/errors/abiParameter.js 804 B
dist/cjs/human-readable/errors/signature.js 420 B
dist/cjs/human-readable/errors/splitParameters.js 404 B
dist/cjs/human-readable/errors/struct.js 338 B
dist/cjs/human-readable/runtime/cache.js 616 B
dist/cjs/human-readable/runtime/signatures.js 777 B
dist/cjs/human-readable/types/signatures-test-d.js 438 B
dist/cjs/human-readable/types/signatures.js 127 B
dist/cjs/human-readable/types/structs.js 127 B
dist/cjs/human-readable/types/utils.js 124 B
dist/cjs/narrow.js 169 B
dist/cjs/regex.js 362 B
dist/cjs/test/abis.js 5.93 kB
dist/cjs/types.js 124 B
dist/cjs/utils.js 124 B
dist/cjs/version.js 149 B
dist/esm/abi.js 62 B
dist/esm/config.js 65 B
dist/esm/errors.js 524 B
dist/esm/human-readable/errors/abiItem.js 454 B
dist/esm/human-readable/errors/abiParameter.js 674 B
dist/esm/human-readable/errors/signature.js 339 B
dist/esm/human-readable/errors/splitParameters.js 345 B
dist/esm/human-readable/errors/struct.js 282 B
dist/esm/human-readable/runtime/cache.js 554 B
dist/esm/human-readable/runtime/signatures.js 567 B
dist/esm/human-readable/types/signatures-test-d.js 365 B
dist/esm/human-readable/types/signatures.js 69 B
dist/esm/human-readable/types/structs.js 66 B
dist/esm/human-readable/types/utils.js 64 B
dist/esm/narrow.js 97 B
dist/esm/regex.js 284 B
dist/esm/test/abis.js 5.8 kB
dist/esm/types.js 64 B
dist/esm/utils.js 64 B
dist/esm/version.js 82 B

compressed-size-action

@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #149 (be322c0) into main (43d3a9d) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head be322c0 differs from pull request most recent head 42346ad. Consider uploading reports for the commit 42346ad to get more accurate results

@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
- Coverage   99.87%   99.87%   -0.01%     
==========================================
  Files          17       17              
  Lines        1632     1614      -18     
  Branches      276      276              
==========================================
- Hits         1630     1612      -18     
  Misses          2        2              
Impacted Files Coverage Δ
src/errors.ts 100.00% <100.00%> (ø)
src/human-readable/errors/abiParameter.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbi.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbiItem.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbiParameter.ts 100.00% <100.00%> (ø)
src/human-readable/parseAbiParameters.ts 100.00% <100.00%> (ø)
src/human-readable/runtime/signatures.ts 100.00% <100.00%> (ø)
src/human-readable/runtime/structs.ts 100.00% <100.00%> (ø)
src/human-readable/runtime/utils.ts 99.36% <100.00%> (-0.01%) ⬇️
src/zod.ts 100.00% <100.00%> (ø)

@tmm tmm marked this pull request as draft June 2, 2023 18:10
Co-authored-by: 0xRaiden <[email protected]>
@tmm tmm marked this pull request as ready for review June 9, 2023 22:08
@tmm tmm merged commit ba21aae into main Jun 9, 2023
@tmm tmm deleted the tmm/overloads branch June 9, 2023 22:44
@github-actions github-actions bot mentioned this pull request Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants