- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 756
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: use union type for traffic search data #9221
chore: use union type for traffic search data #9221
Conversation
Makes the data returned from the traffic search a union type to avoid nasty object-is-undefined errors at runtime. It requires more explicit handling, sure, but it means we don't need to accept undefined.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files |
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.
This is the main part of this PR: change the type to only have a data property if we actually have something. This means we don't need to keep checking "what if data isn't there" means we need to handle it more explicitly.
const totalUsage = calculateTotalUsage(usage); | ||
if (result.state !== 'success') { | ||
return 0; | ||
} | ||
|
||
const totalUsage = calculateTotalUsage(result.data); | ||
return calculateOverageCost( |
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.
Neat!
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.
Cool! 😎
Makes the data returned from the traffic search a union type to avoid
nasty object-is-undefined errors at runtime.
It requires more explicit handling, sure, but it means we don't need
to accept undefined.