简体   繁体   中英

Assigning a DOM object in TypeScript

I'm trying to assign the DOM object of a webpage to a TypeScript variable.

protected DOM_obj : HTMLElement;
DOM_obj = document.defaultView;

I however seem to get the following error:

Type 'Window' is not assignable to type 'HTMLElement'. Property 'accessKey' is missing in type 'Window'.

How would I go about assigning the DOM object of the current window to a TypeScript variable?

As you can see in the TypeScript DOM API here

document.defaultView is of type Window .

So your DOM_obj needs to be of type Window as well:

protected DOM_obj : Window;
DOM_obj = document.defaultView;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM