w3c-web-usb: fix nullable types by dlech · Pull Request #73568 · DefinitelyTyped/DefinitelyTyped · GitHub
Skip to content

w3c-web-usb: fix nullable types#73568

Merged
typescript-bot merged 1 commit into
DefinitelyTyped:masterfrom
dlech:w3c-web-usb-fixes
Sep 6, 2025
Merged

w3c-web-usb: fix nullable types#73568
typescript-bot merged 1 commit into
DefinitelyTyped:masterfrom
dlech:w3c-web-usb-fixes

Conversation

@dlech

@dlech dlech commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: https://wicg.github.io/webusb/
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the package.json.

Additional context:

The first commit fixes errors that were already present when running pnpm test w3c-web-usb. This was needed to be able to actually run tests for the main commit.

The main commit fixes some incorrect types that were observed. According to the WebUSB spec (link above), some properties are nullable, meaning the value can only be null and never undefined. We have also confirmed at runtime in a web browser that these properties do indeed return null.

@typescript-bot

typescript-bot commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Check Config Changes a module config files labels Aug 28, 2025
@typescript-bot

Copy link
Copy Markdown
Contributor

🔔 @larsgk @thegecko @yume-chan — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot moved this to Waiting for Code Reviews in Pull Request Status Board Aug 28, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Aug 28, 2025
@dlech dlech force-pushed the w3c-web-usb-fixes branch from c90458c to a073eaf Compare August 28, 2025 19:41
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in Pull Request Status Board Aug 28, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board Aug 28, 2025

@yume-chan yume-chan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. And can find a device that actually returns null (Microsoft Edge 139, Windows 11):

Image

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Aug 29, 2025
dlech added a commit to afarago/pybricks-code that referenced this pull request Aug 30, 2025
Fix issues with null vs. undefined.

Based on DefinitelyTyped/DefinitelyTyped#73568
dlech added a commit to pybricks/pybricks-code that referenced this pull request Aug 30, 2025
Fix issues with null vs. undefined.

Based on DefinitelyTyped/DefinitelyTyped#73568

@RyanCavanaugh RyanCavanaugh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The eslint changes seem unneeded - neither of those rules are violated in this PR. Please use a line-based suppression if actually needed somewhere

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Owner Approved A listed owner of this package signed off on the pull request. labels Sep 3, 2025
@typescript-bot

Copy link
Copy Markdown
Contributor

@dlech One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you!

@typescript-bot typescript-bot moved this from Needs Maintainer Review to Needs Author Action in Pull Request Status Board Sep 3, 2025
There are certain properties in the WebUSB APIs that are nullable rather
than optional, meaning they can only be null and never undefined.

Fix the types and add a function to the test to validate this.
@dlech dlech force-pushed the w3c-web-usb-fixes branch from a073eaf to 8127560 Compare September 3, 2025 14:04
@typescript-bot typescript-bot removed Revision needed This PR needs code changes before it can be merged. Check Config Changes a module config files labels Sep 3, 2025
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board Sep 3, 2025
@typescript-bot

Copy link
Copy Markdown
Contributor

@RyanCavanaugh, @yume-chan Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@dlech

dlech commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

I just dropped the configuration change commit. Since CI is passing, that tells me that I just have a local problem that was triggering the need for that.

FWIW, this is the error I am seeing locally. It looks like maybe I need to wipe out node_modules and try again.

Error: 
/home/david/work/DefinitelyTyped/types/w3c-web-usb/index.d.ts
  1:1  error  Definition for rule '@typescript-eslint/no-wrapper-object-types' was not found  @typescript-eslint/no-wrapper-object-types
  1:1  error  Definition for rule '@typescript-eslint/no-unsafe-function-type' was not found  @typescript-eslint/no-unsafe-function-type

/home/david/work/DefinitelyTyped/types/w3c-web-usb/w3c-web-usb-tests.ts
  1:1  error  Definition for rule '@typescript-eslint/no-wrapper-object-types' was not found  @typescript-eslint/no-wrapper-object-types
  1:1  error  Definition for rule '@typescript-eslint/no-unsafe-function-type' was not found  @typescript-eslint/no-unsafe-function-type

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Sep 6, 2025
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Waiting for Author to Merge in Pull Request Status Board Sep 6, 2025
@typescript-bot

Copy link
Copy Markdown
Contributor

@dlech: Everything looks good here. I am ready to merge this PR (at 8127560) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@larsgk, @thegecko, @yume-chan: you can do this too.)

@typescript-bot

Copy link
Copy Markdown
Contributor

@RyanCavanaugh Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@dlech

dlech commented Sep 6, 2025

Copy link
Copy Markdown
Contributor Author

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in Pull Request Status Board Sep 6, 2025
@typescript-bot typescript-bot merged commit 596493e into DefinitelyTyped:master Sep 6, 2025
4 checks passed
@dlech dlech deleted the w3c-web-usb-fixes branch September 6, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Owner Approved A listed owner of this package signed off on the pull request. Popular package This PR affects a popular package (as counted by NPM download counts). Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants