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

chore: use union type for traffic search data #9221

Merged
merged 11 commits into from
Feb 5, 2025

Conversation

thomasheartman
Copy link
Contributor

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.

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.
Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 10:48am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Feb 5, 2025 10:48am

Copy link
Contributor

github-actions bot commented Feb 5, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Contributor Author

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.

Comment on lines -36 to 40
const totalUsage = calculateTotalUsage(usage);
if (result.state !== 'success') {
return 0;
}

const totalUsage = calculateTotalUsage(result.data);
return calculateOverageCost(
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

Copy link
Contributor

@daveleek daveleek left a comment

Choose a reason for hiding this comment

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

Cool! 😎

@thomasheartman thomasheartman enabled auto-merge (squash) February 5, 2025 10:47
@thomasheartman thomasheartman merged commit 90e5adb into main Feb 5, 2025
7 of 11 checks passed
@thomasheartman thomasheartman deleted the chore/union-type-for-traffic-search-data branch February 5, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants