question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeviceMotionEvent and DeviceOrientationEvent has lost static function signature requestPermission

See original GitHub issue

(I was referred to this repo by Typescripts main repo issue template)

DeviceMotionEvent and DeviceOrientationEvent has lost static function signature requestPermission in Typescript 4.4

I believe that it should be added back?

Configuration Check

My compilation target is esnext and my lib is lib.dom.d.ts.

Missing / Incorrect Definition

In 4.4.x (and latest nightly build) DeviceMotionEvent and DeviceOrientationEvent has lost its static function signature for requestPermission. This function should be called to trigger permission dialog to collect motion/gyro events. I believe it’s still spec and at least it has to be called in practice. This commit removed definitions in lib.dom.d.ts https://github.com/microsoft/TypeScript/commit/9d443b76aac0832d7f3c890441264d39307fe31a#diff-796971dc74a3f3cd77ca0a3a776d6fe27ab224cd501d9652dbeffcf45ba0f058L4376

Sample Code

DeviceMotionEvent.requestPermission()
DeviceOrientationEvent.requestPermissions()

The change/regression(?) can be tested here by toggling between versions 4.4 and 4.3

Documentation Link

https://www.w3.org/TR/orientation-event/#deviceorientation https://www.w3.org/TR/orientation-event/#devicemotionevent

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TobiasMelencommented, Sep 21, 2021

Ok, i opened this issue believing this was a mistake so i won’t argue. Leaving the following information here for anyone coming from Google:

It’s not possible to get global inference for requestPermission back, the event constructors does not have explicit types to extend. However, adding the following in the file which contains the function invocation currently works.

declare namespace DeviceOrientationEvent {
  function requestPermission(): Promise<PermissionState>
}
declare namespace DeviceMotionEvent {
  function requestPermission(): Promise<PermissionState>
}
0reactions
saschanazcommented, Sep 21, 2021

And if it’s true, please file an issue from this page, it will be helpful!: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent#browser_compatibility

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get DeviceOrientationEvent and DeviceMotionEvent ...
As of iOS 13 beta 2, you need to call DeviceOrientationEvent.requestPermission() to access to gyroscope or accelerometer.
Read more >
Unable to check DeviceOrientationEvent - Apple Developer
It seems that the Safari browser caches the users answer on this (granted, denied). On reloading the page the permission (granted, denied) is...
Read more >
How to requestPermission for devicemotion and ...
To request permission, we would just need to call a method on the DeviceMotionEvent or DeviceOrientationEvent : requestPermission It ...
Read more >
Implement requestPermission() for DeviceOrientationEvent ...
Allows developers to ask for permission to use the Device Orientation and Device Motion APIs. Access to these APIs is currently granted by ......
Read more >
DeviceOrientation Event Specification - W3C
This specification provides several new DOM events for obtaining information about the physical orientation and movement of the hosting device.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found