Skip to content

Conversation

@Mudaafi
Copy link
Contributor

@Mudaafi Mudaafi commented Feb 23, 2024

Updating the types here to match our new, server-side compatible, getUrl implementation


export interface UrlHelpers {
getUrl: () => string;
getUrl: () => string | undefined;
Copy link
Contributor

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?

Copy link
Contributor Author

@Mudaafi Mudaafi Feb 28, 2024

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

Copy link
Contributor

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.

Copy link
Contributor Author

@Mudaafi Mudaafi Feb 28, 2024

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
...
  }
}

Copy link
Contributor

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 😅

Copy link
Contributor

@mocca102 mocca102 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Mudaafi Mudaafi merged commit 8326581 into main Mar 1, 2024
@Mudaafi Mudaafi deleted the nocsl-update-geturl-type branch March 1, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants