-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: update getUrl type #53
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
Conversation
|
|
||
| export interface UrlHelpers { | ||
| getUrl: () => string; | ||
| getUrl: () => string | undefined; |
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.
If it's optional, let's add a question mark instead; what do you think?
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.
It's not that it's optional, but rather that the function can return undefined on server-side. I can modify it to return null instead if that makes more sense. See this PR
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.
Challenge me on this, please if you think otherwise. But I like to reserve undefined for values that haven't been passed or haven't had any operations.
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.
Fair enough, I was thinking along the lines of either
- A function that doesn't have a return value
- On the server --> may as well have not run
getUrl--> Effectively no operations --> undefined
but I'm not too picky about it. I guess a better way to decide is what should getUrl return on the server if it's not supposed to run? In code:
getUrl() {
if (typeof window === 'undefined') {
// Option 1
return; // undefined
// Option 2
return null; // explicitly null
...
}
}
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.
Actually after you laying out like this, not sure anymore 😅
mocca102
left a comment
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.
LGTM!
Updating the types here to match our new, server-side compatible, getUrl implementation