-
Notifications
You must be signed in to change notification settings - Fork 101
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
fix: typescript type for ScriptReducerAction
#113
Conversation
src/ScriptContext.tsx
Outdated
@@ -19,9 +19,11 @@ enum SCRIPT_LOADING_STATE { | |||
RESOLVED = "resolved", | |||
} | |||
|
|||
type ScriptLoadingState = `${SCRIPT_LOADING_STATE}`; |
There was a problem hiding this comment.
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:
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]; |
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @leogedler! 💯
ScriptLoadingState
type from the union of the enumSCRIPT_LOADING_STATE
and used itas a possible values for
setLoadingStatus
to avoid type error when passing a valid string value on the dispatch function.