-
Notifications
You must be signed in to change notification settings - Fork 9
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
Replace functions returning explicit undefined
value
#77
Comments
I would add this practice as well: before if (num === undefined) {
return "";
}
return String(num); after if (!num) {
return "";
}
return String(num); or more fancy export const numStr = (num: number | undefined): string => String(num ?? "");
console.log(numStr(1));
console.log(numStr(0));
console.log(numStr(undefined)); |
I am not a fan of generic rules applied without reasoning. If there is a specific block of code where we consider we can achieve better readability, usability, performance, etc. then let's do it; let's open a PR and we can discuss what we are solving with that code change. |
I think this is related with @gildub issue description to avoid runtime error reactwg/react-18#75 |
For this we would need to enable the lint https://github.com/trustification/trustify-ui/blob/main/.github/workflows/ci-actions.yaml#L29
I have no idea if there are other rules for this, react-related |
Undefined means no value has been assigned where null means an empty value.
It's a good practice to return and propagate a null value instead of using
undefined
because it requires to handle the special type case ofundefined
in the caller.The text was updated successfully, but these errors were encountered: