2

I wanted to use HTMLDialogElement in a typescript project in VS Code.

But when using this class, it first shows a deprecation "this is not available in most browsers". However when looking at MDN browser compatibility, it looks commonly spread, and I don't really care to make it work on IE.

But then when trying to use the common dialog functions (show(), showModal(), close()), they are simply not available for autocomplete, and thus shows error. After looking at my lib.dom.d.ts, the HTMLDialogElement definition looks like this :

/** @deprecated this is not available in most browsers */
interface HTMLDialogElement extends HTMLElement {
    addEventListener<K extends keyof HTMLElementEventMap>((...) => ...): void;
    addEventListener(...): void;
    removeEventListener<K extends keyof HTMLElementEventMap>(...): void;
    removeEventListener(...): void;
}

So as expected, no definition for show(), showModal() and close().

However the last comment from this github issue shows that the methods I mentionned above are present in Typescript.

Is there a way to update the lib.dom.d.ts file used by VS Code, or the problem is elsewhere?

Franck Bigand
  • 152
  • 2
  • 9

1 Answers1

2

This is fixed in typescript 4.7.

If you are already using typescript 4.7 and still sees the deprecated warning, make sure to check your vscode is using typescript 4.7. You can find more information on checking the typescript version in vscode here: What TypeScript version is Visual Studio Code using? How to update it?

If updating typescript doesnt work for some reason, you can add a typescript definition as a workaround. https://gist.github.com/jbmoelker/226594f195b97bf61436

jkpark
  • 253
  • 1
  • 9