Skip to content

Bug in lib.dom.d.ts - document.evaluate #26437

@ststeiger

Description

@ststeiger

In TypeScript (my version is 2.5), lib.dom.d.ts specifies document.evaluate as follows:
evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | null, type: number, result: XPathResult | null): XPathResult;

where

interface XPathNSResolver {
    lookupNamespaceURI(prefix: string): string;
}

So this means the following code

xmldoc.evaluate(
    '//ns1:RunLocatorResponse',
    xmldoc,
    function (prefix:string) : string {
        if (prefix === 'ns1')
            return 'http://tempuri.org/AWEService/API/WASAPI';
        else
            return null;
    },
    XPathResult.ANY_TYPE,
    null
);

reports function (prefix:string) : string cannot be assigned to XPathNSResolver.

However, as in the comments of this issue under note of DOM-Level-3-XPath-20040226 the DOM spec clearly says

Note: The parameter resolver of the method XPathEvaluator.evaluate is specified as an object that implements the XPathNSResolver interface. ECMAScript users can also pass to this method a function which returns a String and takes a String parameter instead of the resolver parameter.

So libdom.d.ts is missing an overload for
(prefix:string) => string
and that leads to a error-message for proper ECMAScript which is not transpiling, which is a bug.

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixed in TSJS repoFix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yetGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions