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

fix: typescript type for ScriptReducerAction #113

Merged
merged 2 commits into from
May 15, 2021

Conversation

leogedler
Copy link
Contributor

  • Created ScriptLoadingState type from the union of the enum SCRIPT_LOADING_STATE and used it
    as a possible values for setLoadingStatus to avoid type error when passing a valid string value on the dispatch function.

@leogedler leogedler requested a review from a team as a code owner May 14, 2021 22:49
@@ -19,9 +19,11 @@ enum SCRIPT_LOADING_STATE {
RESOLVED = "resolved",
}

type ScriptLoadingState = `${SCRIPT_LOADING_STATE}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

@leogedler I was reading up on enums and I think we should get rid of it and replace it with the following:

Suggested change
type ScriptLoadingState = `${SCRIPT_LOADING_STATE}`;
const SCRIPT_LOADING_STATE = {
INITIAL: "initial",
PENDING: "pending",
REJECTED: "rejected",
RESOLVED: "resolved",
} as const;
type ScriptLoadingState = typeof SCRIPT_LOADING_STATE[keyof typeof SCRIPT_LOADING_STATE];

https://stackoverflow.com/a/60041791

Copy link
Contributor Author

@leogedler leogedler May 15, 2021

Choose a reason for hiding this comment

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

@gregjopa got it, make sense the explanation why is better to use a const.

I have pushed the suggested change.

@codecov
Copy link

codecov bot commented May 15, 2021

Codecov Report

Merging #113 (3d5e1e9) into main (86398e9) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #113      +/-   ##
==========================================
+ Coverage   94.33%   94.37%   +0.03%     
==========================================
  Files           4        4              
  Lines         159      160       +1     
  Branches       56       56              
==========================================
+ Hits          150      151       +1     
  Misses          9        9              
Impacted Files Coverage Δ
src/ScriptContext.tsx 96.15% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86398e9...3d5e1e9. Read the comment docs.

Copy link
Contributor

@gregjopa gregjopa left a comment

Choose a reason for hiding this comment

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

Thanks @leogedler! 💯

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.

None yet

2 participants