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?
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?
use this
export type DOMElement = globalThis.Element
lib.dom
has already imported Element
type for you, you can explicitly access that from globalThis
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'
From the global.d.ts:
/*
React projects that don't include the DOM library need these interfaces to compile.
React Native applications use React, but there is no DOM available. The JavaScript runtime
is ES6/ES2015 only. These definitions allow such projects to compile with only `--lib ES6`.
Warning: all of these interfaces are empty. If you want type definitions for various properties
(such as HTMLInputElement.prototype.value), you need to add `--lib DOM` (via command line or tsconfig.json).
*/
Just follow it, add 'compilerOptions/lib/dom' to the tsconfig.json.
Thanks to Zunaib, I found the correct solution to my problem.
In a file, define:
export interface Element2 extends Element {}
then:
import { Element2 } from 'path1';
import { Element } from 'path2';