This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): refactor ScalarEnums in codecs (#2100)
This PR refactors the definition of a "Scalar Enum" in the context of codecs which unlocks stricter types and adds support for hybrid scalar enums (both numeric and lexical). - The `ScalarEnum` type now simply defines the "lookup object" created by the `enum` constructor. - The `ScalarEnumFrom<T>` and `ScalarEnumTo<T>` types describe the input/output to encode/decode respectively, given a `enum` constructor. - The Scalar Enum `Encoder`, `Decoder` and `Codec` functions now use these types to create stronger type constraints. This means, TypeScript will now fail if we provide the wrong key or value for the enum. - The `getScalarEnumStats` helper function was also updated to provide non-duplicated keys and values for the `enum` constructor. Whilst it was not an issue for full-numeric or full-lexical enums, the previous implementation made it impossible to encode/decode hybrid enums. Tests were added for that scenario. As an added bonus, this PR should make the closed PR #2091 obsolete.
- Loading branch information
1 parent
1a0940d
commit 606040b
Showing
4 changed files
with
141 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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