add types of devtools-detect

This commit is contained in:
york yao
2016-08-12 20:40:18 +08:00
parent 1003a9ce52
commit 2f0120be92
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
/// <reference path="devtools-detect.d.ts" />
// check if it's open
console.log('is DevTools open?', window.devtools.open);
// check it's orientation, null if not open
console.log('and DevTools orientation?', window.devtools.orientation);
// get notified when it's opened/closed or orientation changes
window.addEventListener('devtoolschange', function (e) {
console.log('is DevTools open?', e.detail.open);
console.log('and DevTools orientation?', e.detail.orientation);
});

16
devtools-detect/devtools-detect.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
// Type definitions for ajv
// Project: https://github.com/sindresorhus/devtools-detect
// Definitions by: York Yao <https://github.com/plantain-00/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type DevTools = {
open: boolean;
orientation: "vertical" | "horizontal";
}
interface DevToolsEvent extends Event {
detail: DevTools;
}
interface Window {
devtools: DevTools;
addEventListener(type: "devtoolschange", listener: (ev: DevToolsEvent) => any, useCapture?: boolean): void;
}