You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a pain to have to import the enums used in props for certain components rather than just be able to let IntelliSense tell yo which strings are valid. TS can prevent invalid values of string types if the valid values are provided in a union type.
We should also consider watching out for the advice against booleans for state, but I'm not sure that's as important.
The text was updated successfully, but these errors were encountered:
Hmm, I think that helps with cases where we have more than one prop and only certain combinations of those props are valid, but for this issue I was just thinking of the basic case where we have e.g. statusType: StatusType and we could instead have statusType: 'error' | 'warning' | 'info' | 'loading' so when we consume the component we don't need to import the enum and we can just pass a string, so intellisense works right away instead of waiting for you to add the import. Like the AuthenticationStates example in the article.
I'm still wrapping my head around the best-of-both-worlds approach, is the benefit of keeping enums in there just so it's more searchable?
@mturley, I was keen to work on it because it seems to be a good practice to make code more robust by enforcing types. And also because it allows me to get stronger with types.
This will be a breaking change, and it's just a code cleanliness thing, but I think it'd be better to get it in sooner rather than later. Based on a discussion with @gildub a while back where he shared this article with me: https://blog.logrocket.com/put-the-typescript-enums-and-booleans-away/
It is a pain to have to import the enums used in props for certain components rather than just be able to let IntelliSense tell yo which strings are valid. TS can prevent invalid values of string types if the valid values are provided in a union type.
We should also consider watching out for the advice against booleans for state, but I'm not sure that's as important.
The text was updated successfully, but these errors were encountered: