refactor: ban TypeScript enums across internal-snaps - #213
Draft
ulissesferreira wants to merge 1 commit into
Draft
refactor: ban TypeScript enums across internal-snaps#213ulissesferreira wants to merge 1 commit into
ulissesferreira wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Convert all locally-declared
enumandconst enumdeclarations toas constobjects 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
What changed
as constobjects + derived union typesno-restricted-syntaxrule added to banTSEnumDeclarationArray.includes()typingBreaking changes
Enumis now a union of string/number literals instead of a nominal enum typetypeof Enum.Memberin type positions now refers to literal values instead of enum member typesEnum.Member) works the same wayNot included
@metamask/utils,@metamask/keyring-api, etc.) are untouchedValidation
tsc --noEmitpasses (only pre-existing baseline errors remain)enumdeclarations remaining inpackages/dist/bundle.jsbuild — pre-existing requirement)