Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TS2339: Property 'msMatchesSelector' does not exist on type 'Element' [duplicate]

Tags:

typescript

In spec.ts For Example: Dom.spec.ts

  describe('matchesSelector', () => {
    let result: boolean;
    let matchelement: HTMLElement;
it('Matches for the opera browser', () => {
        matchelement.matches = matchelement.msMatchesSelector = null;
        result = Dom.matches(matchelement, '#match');
        expect(result).toBe(true);
    });

when calling msmatchesSelector in matchelement.msMatchesSelector in above code it fetch the specfic type in lib.dom.ts . It reproduce the below error when I uprade the typescript version to 3.0

spec\dom.spec.ts(304,49): error TS2339: Property 'msMatchesSelector' does not exist on type 'HTMLElement'.

But It works fine in my previous typescript version 2.6.2

like image 204
Vijay VJ Avatar asked Oct 08 '18 05:10

Vijay VJ


1 Answers

This is a breaking change between 3.0 and 3.1:

TypeScript's built-in .d.ts library (lib.d.ts and family) is now partially generated from Web IDL files from the DOM specification. As a result some vendor-specific types have been removed.

The recommendation is to extend the built-in definitions as needed:

If your run-time guarantees that some of these names are available at run-time (e.g. for an IE-only app), add the declarations locally in your project, e.g.: For Element.msMatchesSelector, add the following to a local dom.ie.d.ts

interface Element {
    msMatchesSelector(selectors: string): boolean;
}
like image 165
Titian Cernicova-Dragomir Avatar answered Sep 28 '22 06:09

Titian Cernicova-Dragomir