Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import an interface from lib.dom.d.ts?

Tags:

typescript

I need to define a Element interface in my code:

interface Element {
    // my declaration
}

But, I also need to access the Element type of lib.dom.d.ts.

How could I do?

like image 409
Lucas Willems Avatar asked Feb 10 '20 12:02

Lucas Willems


People also ask

What is lib d ts?

A special declaration file lib. d. ts ships with every installation of TypeScript. This file contains the ambient declarations for various common JavaScript constructs present in JavaScript runtimes and the DOM. This file is automatically included in the compilation context of a TypeScript project.


2 Answers

use this

export type DOMElement = globalThis.Element

lib.dom has already imported Element type for you, you can explicitly access that from globalThis

like image 170
user7670223 Avatar answered Sep 19 '22 10:09

user7670223


Export your interface first to be able to import it because all definition files should export types and interfaces.

export interface Element {
    // my declaration
}

And then import as will

import {Element} from 'path'
import {Element as ABC} from 'path'
like image 34
Zunaib Imtiaz Avatar answered Sep 22 '22 10:09

Zunaib Imtiaz