TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Missing "lock" method in ScreenOrientation

Open mistic100 opened this issue 2 years ago • 12 comments

I just updated from 5.1.3 to 5.2.2 and I cannot compile anymore because the "lock" method was removed from the ScreenOrientation interface.

I don't think this is correct.

This is the change https://github.com/microsoft/TypeScript/pull/54725/files#diff-dc0eab937d15e62545da3ed7b4f40ad6b24f15dd88fbc6ceda2bfb4ed8356eb0L20901

MDN : https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock

ping @sandersn

thanks

mistic100 avatar Aug 28 '23 08:08 mistic100

Hmm it seems it's because it falls under the "two major browsers" threshold since Firefox removed it (duh !). However Chrome Android having the majority of the smartphone market wouldn't it make sense to keep it ?

mistic100 avatar Aug 28 '23 08:08 mistic100

for those who experience this compilation error, you may change to this alternative syntax to bypass the compiler error:

window.screen.orientation['lock']('landscape');

richso avatar Nov 24 '23 11:11 richso

@saschanaz I am running into the same problem. This is an obvious regression and should be corrected ASAP.

tsukumijima avatar Dec 31 '23 00:12 tsukumijima

hello,

I am facing this issue, can't wait for the fix. the temp solution from @richso is not working on my angular project.

liyokuna avatar Jan 18 '24 14:01 liyokuna

@liyokuna As a temporary solution I change the source codes of this lib inside VSCode, so the error stops happening, but every time I update VSCode I need to adjust the source code again, as the source code is inside the VScode folder installed on the my computer.

It's not a recommended solution, but this way VScode stops reporting unnecessary and incorrect errors. This only works for VScode.

eduardo-mior avatar Jan 18 '24 15:01 eduardo-mior

thanks for the answer but @eduardo-mior i'm on intelli j unfortunately :|

liyokuna avatar Jan 18 '24 16:01 liyokuna

or just add // @ts-ignore before the line

mistic100 avatar Jan 18 '24 16:01 mistic100

I think the correct way would be adding the now missing interface locally in one of your .ts or .d.ts files:

type OrientationLockType = "any" | "landscape" | "landscape-primary" | "landscape-secondary" | "natural" | "portrait" | "portrait-primary" | "portrait-secondary";
interface ScreenOrientation extends EventTarget {
    lock(orientation: OrientationLockType): Promise<void>;
}

HolgerJeromin avatar Jan 18 '24 16:01 HolgerJeromin

yep did that, @mistic100 but i thnik my issue is maybe somewhere else in my ngular project...

liyokuna avatar Jan 18 '24 16:01 liyokuna

Placing that into a d.ts file included in your project will also augment the global types and allow things to work. You definitely do not need to be overwriting any files in VS Code or node_modules to add things to the globals like this.

jakebailey avatar Jan 18 '24 17:01 jakebailey

the main issue is that unlock is there, while lock was removed. even if there is a valid reason to remove lock, it should be consistent, since both of the methods have the same support.

Knagis avatar Feb 29 '24 14:02 Knagis

To be fair both method don't have the same support.

https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock#browser_compatibility
https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/unlock#browser_compatibility

mistic100 avatar Feb 29 '24 14:02 mistic100