-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
No type info available except "isEnabled" #158
Comments
Per readme, you have to guard the usage: if (screenfull.isEnabled) {
screenfull.request();
} |
That is some smart typing. Really neat. I learned something today :-). I'll explain it to anyone who comes across this issue and scratches their head, like I have: declare const screenfull: screenfull.Screenfull | {isEnabled: false}; This type definition prevents users from using It works, because if the user uses If the user checks |
If you don't want to wrap all your screenfull API calls with an if guard statement, you call also use an assertion function (provided that you use TS >= 3.7) : function assert(condition: boolean, message?: string): asserts condition {
if (!condition) {
// eslint-disable-next-line no-console
console.trace();
throw new Error(message);
}
}
// Some button in your DOM to switch to fullscreen :
const switchToFullScreenButton: HTMLButtonElement = .... ;
switchToFullScreenButton.addEventListener('click', handleClickOnFullscreenButton);
switchToFullScreenButton.disabled = !screenfull.isEnabled;
function handleClickOnFullscreenButton(): void {
// Here you expect screenfull.isEnabled to be true, so you can assert :
assert(screenfull.isEnabled);
// In the rest of the code of this handler, you can use the complete screenfull API,
if (screenfull.isFullscreen) {
screenfull.exit();
} else {
screenfull.request(someElement);
}
} |
Any property besides
isEnabled
gives an error like this (same forrequest
,on
,exit
, etc):Issue is solved if I change:
https://github.com/sindresorhus/screenfull.js/blob/b2a50cc4d1554ef62530a4cae973096a96921c93/src/screenfull.d.ts#L157
to:
The text was updated successfully, but these errors were encountered: