Use for questions about using, extending, and manipulating the TypeScript DOM standard definitions library contained in the lib.dom.d.ts declaration file and lib.dom.iterable.d.ts for iterable DOM APIs.
Questions tagged [typescript-lib-dom]
7 questions
212
votes
14 answers
How to assert a type of an HTMLElement in TypeScript?
I'm trying to do this:
var script:HTMLScriptElement = document.getElementsByName("script")[0];
alert(script.type);
but it's giving me an error:
Cannot convert 'Node' to 'HTMLScriptElement': Type 'Node' is missing property 'defer' from type…
![](../../users/profiles/204555.webp)
Spongman
- 8,493
- 7
- 34
- 55
4
votes
1 answer
Is there no SubmitEvent interface in Typescript?
TypeScript has different interfaces mapping DOM events. (e.g. KeyboardEvent, MouseEvent, etc.). We can find them here.
For instance, they are handy in Angular when receiving an event's payload in an event listener.
I have been a bit surprised to be…
![](../../users/profiles/811120.webp)
Vincent Pazeller
- 1,008
- 13
- 25
3
votes
1 answer
Reference TypeScript dom lib types locally
Several types from TypeScript built-in DOM lib needs to be used in local module for cross-platform code piece, e.g.:
// foo.ts
export let foo: EventListener = (e) => ...;
This can be achieved by adding:
///
The problem is…
![](../../users/profiles/3731501.webp)
Estus Flask
- 150,909
- 47
- 291
- 441
3
votes
1 answer
Type 'HTMLFormControlsCollection' has no property 'x' and no string index signature
The following error appears when trying to destructure a form.elements object:
Type 'HTMLFormControlsCollection' has no property 'x' and no string index signature
// in a class
domRefs: {[key: string]: HTMLFormElement | null} = {
myForm:…
![](../../users/profiles/985454.webp)
Qwerty
- 19,992
- 16
- 88
- 107
1
vote
2 answers
How to fix the "Cannot find name 'ClipboardItem'" error?
Getting the error
error TS2304: Cannot find name 'ClipboardItem'
when trying to create a ClipboardItem for navigator.clipboard.write().
const clipboardItemInput = new ClipboardItem({'image/png' : blobInput});
await…
![](../../users/profiles/13301283.webp)
sadasmita biswal
- 11
- 2
1
vote
1 answer
How to avoid conflict between "dom" and "webworker" libs?
I am using TypeScript with React, and one of the things I want to achieve is background sync for offline support.
To enable typings for service worker, I have to include the WebWorker lib, but it conflicts with DOM lib and produces an error:
(25,1):…
![](../../users/profiles/6683308.webp)
Shunxu Huang
- 41
- 3
1
vote
1 answer
How to use Typescript DOM lib on the server?
I am writing code for a Google cloud function. Here I want to use the URL standard including URLSearchParams. I found out that they are part of the TypeScript DOM lib, so I've added that to my tsconfig lib setting.
However, when I compile and deploy…
![](../../users/profiles/294632.webp)
Thijs Koerselman
- 16,219
- 15
- 62
- 89