Skip to main content

isWindow

A function that checks whether a given argument is the window object, and if so, narrows the type of the argument to Window.


Code

🔗 View source code

Interface

typescript
function isWindow(element: unknown): element is Window

Usage

typescript
import { isWindow } from '@modern-kit/utils';

const div = document.createElement('div');

isWindow(window); // true

isWindow(window.document); // false
isWindow({}); // false
isWindow(div); // false
isWindow(1); // false
isWindow(''); // false