Implementing a gyroscope permission request, but i get a typescript error on requestPermission
My code:
if (typeof (DeviceMotionEvent) !== 'undefined' && typeof (DeviceMotionEvent.requestPermission) === 'function') {
return DeviceMotionEvent.requestPermission()
.then((response: string) => response === 'granted');
}
TS2339: Property 'requestPermission' does not exist on type '{ new (type: string, eventInitDict?:
DeviceMotionEventInit): DeviceMotionEvent; prototype: DeviceMotionEvent; }'.
Struggling a bit with this one. i tried casting request permission like this (DeviceMotionEvent.requestPermission() as any) but it stays the same. Since it's not a module i cannot just do yarn add @types/...
You need to cast the Object, not the function, try this:
(DeviceMotionEvent as any).requestPermission()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With