[utils] Ban enums, and replace them with alternatives
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 65/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in packages/utils at src/caip-types.ts:134, src/misc.ts:137, and src/time.ts:4 to inspect the three exported enums and their call sites. Replace them with const objects and derived union types while preserving call-site behavior, and adapt the lint rule to core's shared configuration. Done means the enum exports are structural and the breaking change is prepared for a major release.
Written by the indexing model from the issue text.
Description
Carried over from https://github.com/MetaMask/utils/pull/280, which was approved but still open when @metamask/utils moved into core.
TypeScript is structurally typed nearly everywhere, but enums are nominal. Two enums that look identical are not assignable to each other, so a value produced by one copy of a package fails to typecheck against a function from another copy. That bites hardest in a monorepo with duplicated versions in the tree.
packages/utils still exports three:
KnownCaipNamespaceinsrc/caip-types.ts:134JsonSizeinsrc/misc.ts:137Durationinsrc/time.ts:4
The original PR replaces them with const objects plus derived union types, which keeps the call sites working while making the types structural.
Note this is a breaking change for consumers who use the enum types nominally, so it wants a major. The PR's .eslintrc.js rule does not port directly since core has its own shared config.
- Dominant language
- TypeScript
- Stars
- 422
- Forks
- 313
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 414
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MetaMask/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
CI: "Validate changelog diffs" job fails on every fork-sourced pull requestPossibly taken @Roxen-AS claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
platform-api-docs: `scan` strategy misses ESM-only packages, which ship `.d.ts` rather than `.d.cts`Possibly taken @gaohan1994 claimed this 21 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
[utils] Replace the `uuid` dependency with `crypto.randomUUID()`Possibly taken @avantikonde claimed this 34 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
MetaMask/core#10210 · 1 reaction ·
Maintainers usually reply within 1 day
-
[utils] `toWei` accepts fractional wei and returns wrong valuesPossibly taken @Roxen-AS claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
Similar issues
-
enhancement module: library-ui
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
chthollyphile/folia-major#1206 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
typescript-eslint/typescript-eslint#13189 ·
Maintainers usually reply within 2 days
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Cotal-AI/Cotal#6442 · 2 comments ·
Maintainers usually reply within 1 day
-
wrong type
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
elastic/elasticsearch-specification#6919 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day