Skip to content

refactor: ban TypeScript enums across internal-snaps - #213

Draft
ulissesferreira wants to merge 1 commit into
mainfrom
refactor/ban-enums
Draft

refactor: ban TypeScript enums across internal-snaps#213
ulissesferreira wants to merge 1 commit into
mainfrom
refactor/ban-enums

Conversation

@ulissesferreira

Copy link
Copy Markdown
Contributor

Summary

Convert all locally-declared enum and const enum declarations to as const objects with derived union types (Pattern A), and add an ESLint rule banning new enums.

Refs: MetaMask/utils#280, MetaMask/eslint-config#417

Changes

Packages affected

  • bitcoin-wallet-snap: 10 enums converted
  • solana-wallet-snap: 16 enums converted
  • tron-wallet-snap: 11 enums converted
  • stellar-wallet-snap: converted (deferred, partially applied — not yet complete)

What changed

  • All locally-declared TypeScript enums converted to as const objects + derived union types
  • ESLint no-restricted-syntax rule added to ban TSEnumDeclaration
  • Type fixes for template literal types, namespace usage patterns, and Array.includes() typing
  • Changelogs added for bitcoin, solana, and tron packages

Breaking changes

  • Type signatures change: Enum is now a union of string/number literals instead of a nominal enum type
  • typeof Enum.Member in type positions now refers to literal values instead of enum member types
  • Runtime values unchanged: Member access (Enum.Member) works the same way

Not included

  • Stellar package is incomplete — has half-applied fixes, needs full completion before merge
  • Unit tests require built bundles (pre-existing infrastructure requirement)
  • External/imported enums (from @metamask/utils, @metamask/keyring-api, etc.) are untouched

Validation

  • ✅ Per-package tsc --noEmit passes (only pre-existing baseline errors remain)
  • ✅ ESLint clean on all changed files
  • ✅ oxfmt formatting verified
  • ✅ Zero enum declarations remaining in packages/
  • ⚠️ Unit tests skipped (require dist/bundle.js build — pre-existing requirement)

Convert all locally-declared `enum` and `const enum` declarations
to `as const` objects with derived union types (Pattern A).

**BREAKING CHANGES:**
- Type signatures change: `Enum` is now a union of string/number
  literals instead of a nominal enum type
- `typeof Enum.Member` expressions in type positions now refer to
  literal values instead of enum member types

**Packages affected:**
- bitcoin-wallet-snap: 10 enums converted
- solana-wallet-snap: 16 enums converted
- tron-wallet-snap: 11 enums converted
- stellar-wallet-snap: converted (deferred, partial)

**Also included:**
- ESLint rule banning new `TSEnumDeclaration` via `no-restricted-syntax`
- Changelogs for bitcoin, solana, and tron packages
- Type fixes for template literal types, namespace usage patterns,
  and array .includes() typing after enum-to-const conversion

Refs: MetaMask/utils#280, MetaMask/eslint-config#417
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.

1 participant