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

Update methods on Page type to return Promises #48

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

allansson
Copy link

Please fill in this template.

Copy link

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

Nicely done! LGTM 🚀

@@ -2570,7 +2570,7 @@ export interface Page {
* `https://`.
* @param options
*/
goto(url: string, options?: NavigationOptions): Promise<null | Response>;
goto(url: string, options?: NavigationOptions): Promise<Response | null>;
Copy link

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?

Copy link
Author

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:

  1. Complex, named types
  2. Primitives
  3. null and undefined

For example:

function abc(): Alphabet | string | null

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

Copy link
Author

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.

Copy link
Author

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

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice work 🙇

@allansson allansson merged commit 832f688 into master-async-browser Jun 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants