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

fix: mark context.request.loadedUrl and id as required inside the request handler #2531

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Jun 11, 2024

The properties are still optional in other places like preNavigationHooks.

@B4nan B4nan added the adhoc Ad-hoc unplanned task added during the sprint. label Jun 11, 2024
@github-actions github-actions bot added this to the 91st sprint - Tooling team milestone Jun 11, 2024
@github-actions github-actions bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Jun 11, 2024
@B4nan B4nan force-pushed the required-request-loaded-url branch 2 times, most recently from 0baee66 to 32aaf20 Compare June 11, 2024 19:48
…uest/error handler

The properties are still optional in other places like `preNavigationHooks`.
@B4nan B4nan force-pushed the required-request-loaded-url branch from 32aaf20 to d30e84b Compare June 11, 2024 19:50
@B4nan B4nan merged commit 2b54660 into master Jun 11, 2024
9 checks passed
@B4nan B4nan deleted the required-request-loaded-url branch June 11, 2024 20:04
Comment on lines +265 to +266
// test that `request.loadedUrl` is no longer optional
expect(request.loadedUrl.length).toBe(sources[0].length);
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. does the comment have to be there? it makes sense in the context of this PR, but later on, I think it won't be necessary
  2. why do you need to check the length instead of just comparing the string values?

Copy link
Member Author

Choose a reason for hiding this comment

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

the test checks if loadedUrl is typed to string and not string | undefined which the latter would fail to compile here. you wont verify that if you compare the value, you need to call something on the value. the comment is there to explain this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, then the comment failed 😄 Why not check typeof then?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the very same story, the test is about type level, not runtime values, those were correct already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I get it now. I guess there's no way to do expect, but on the type level. Could we reword the comment to something like "Check that request.loadedUrl cannot not undefined. If it could, accessing the length property would cause a Typescript error."?

Copy link
Member Author

Choose a reason for hiding this comment

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

there are ways to test on type level too, often its about making assignments to explicitly typed variables (combined with using @ts-expect-error for cases that should fail). we could do the same here too. or we could use something like https://github.com/dsherret/conditional-type-checks

few examples of such tests here https://github.com/mikro-orm/mikro-orm/blob/master/tests/types.test.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

conditional-type-checks is pretty cool, if you think it's worth adopting it for cases like this, I'm in favor

packages/core/src/router.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants