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

refactor: switch typeof undefined checks with strict comparison of the value undefined #7006

Merged
merged 3 commits into from
Mar 2, 2024

Conversation

TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Mar 2, 2024

No description provided.

Copy link

vercel bot commented Mar 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Mar 2, 2024 11:10am

Copy link

nx-cloud bot commented Mar 2, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f19a867. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

typeof defaultedOptions.networkMode === 'undefined' &&
defaultedOptions.persister
) {
if (!defaultedOptions.networkMode && defaultedOptions.persister) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

networkMode is a string literal type so doing the simplified ! check should be safe. We can't do that for the above booleans obviously

Copy link

codesandbox-ci bot commented Mar 2, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f19a867:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

typeof fetchStatus !== 'undefined' &&
fetchStatus !== query.state.fetchStatus
) {
if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here: fetchStatus is not a boolean, we just need to check if it was passed

@SergioMorchon
Copy link

SergioMorchon commented Mar 2, 2024

It may be handy to use a more semantic utility with a positive naming convention.
Something like

const isDefined = <Value>(value: Value | null | undefined): value is Value =>
  value !== null && value !== undefined;

Adding or not the null check here should also be considered, I don't know the impact on the APIs if there is any difference between passing a null value vs passing undefined value vs ommiting a parameter.

@TkDodo
Copy link
Collaborator Author

TkDodo commented Mar 2, 2024

We can't check for null because data can be null - it just can't be undefined

@TkDodo TkDodo merged commit 11e9650 into main Mar 2, 2024
5 checks passed
@TkDodo TkDodo deleted the feature/typeof_undefined branch March 2, 2024 13:08
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.

None yet

2 participants