-
Notifications
You must be signed in to change notification settings - Fork 5
Update methods on Page type to return Promises #48
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
ankur22
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.
Nicely done! LGTM 🚀
| * @param options | ||
| */ | ||
| goto(url: string, options?: NavigationOptions): Promise<null | Response>; | ||
| goto(url: string, options?: NavigationOptions): Promise<Response | 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.
This ordering makes more sense. Is this also idiomatic?
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.
I would say so, yes.
My gut feeling for how it "should" be is:
- Complex, named types
- Primitives
nullandundefined
For example:
function abc(): Alphabet | string | nullThe point is to keep the thing that the user is looking for up front, so that it's easier to find functions that return what you want. And you're unlikely to want to use a function because it returns null or 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.
The counter-argument is that you should draw attention to the exceptional value (null, undefined or custom error types) to highlight the fact that the function has some special cases that you need to handle.
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.
But what I see most often is that null and undefined go at the end. 🙂
inancgumus
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.
Nice work 🙇
Please fill in this template.
pnpm test <package to test>.