Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/replace enums with companion pattern approach #1083

Conversation

lukasaric
Copy link
Contributor

@lukasaric lukasaric commented Apr 17, 2024

Solves #1077

Motivation and Resolution

To increase the type safety, this PR introduces the enum replacement with the companion pattern approach.
To have a better understanding, here's a good thread on why it would be good to avoid enums in TS

Don't use Enums in Typescript, they are very dangerous

RPC version (if applicable)

Usage related changes

n.a

Development related changes

Here's the example of before vs after usage:

BEFORE

export enum NetworkName {
  SN_MAIN = 'SN_MAIN',
  SN_GOERLI = 'SN_GOERLI',
  SN_SEPOLIA = 'SN_SEPOLIA',
}

AFTER

export const NetworkName = {
  SN_MAIN: 'SN_MAIN',
  SN_GOERLI: 'SN_GOERLI',
  SN_SEPOLIA: 'SN_SEPOLIA',
} as const;

// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type
export type NetworkName = (typeof NetworkName)[keyof typeof NetworkName];

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@lukasaric lukasaric marked this pull request as draft April 17, 2024 06:10
@lukasaric lukasaric changed the base branch from develop to next-version April 17, 2024 07:47
@lukasaric lukasaric changed the base branch from next-version to develop April 17, 2024 07:47
Luka Saric added 3 commits April 17, 2024 10:55
…n-approach

# Conflicts:
#	src/types/api/rpcspec_0_7/nonspec.ts
#	src/wallet/account.ts
#	src/wallet/connect.ts
src/constants.ts Outdated Show resolved Hide resolved
@ivpavici ivpavici requested a review from tabaktoni May 6, 2024 13:14
semantic-release-bot and others added 2 commits May 21, 2024 08:44
# [6.9.0](starknet-io/starknet.js@v6.8.0...v6.9.0) (2024-05-21)

### Bug Fixes

* cannot infer ts2742 types from starknet-types@0.7 ([starknet-io#1098](starknet-io#1098)) ([f1c3b8e](starknet-io@f1c3b8e))
* remove [warning] from typedoc for external usage ([starknet-io#1095](starknet-io#1095)) ([195186f](starknet-io@195186f)), closes [starknet-io#1121](starknet-io#1121) [starknet-io#1126](starknet-io#1126)

### Features

* add type coverage ([starknet-io#1120](starknet-io#1120)) ([eceda5d](starknet-io@eceda5d))
* provider.getL1MessageHash ([starknet-io#1123](starknet-io#1123)) ([1489cf2](starknet-io@1489cf2))

### Reverts

* Revert "chore: add examples to JsDoc for transaction.ts file (starknet-io#1105)" (starknet-io#1108) ([59eb01e](starknet-io@59eb01e)), closes [starknet-io#1105](starknet-io#1105) [starknet-io#1108](starknet-io#1108)
@lukasaric lukasaric marked this pull request as ready for review May 23, 2024 14:21
Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ivpavici ivpavici changed the base branch from develop to next-version May 31, 2024 08:57
@ivpavici ivpavici merged commit 70a6dab into starknet-io:next-version May 31, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending need update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants