Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在typescript中声明getAttribute函数类型_Javascript_Node.js_Typescript - Fatal编程技术网

Javascript 如何在typescript中声明getAttribute函数类型

Javascript 如何在typescript中声明getAttribute函数类型,javascript,node.js,typescript,Javascript,Node.js,Typescript,我正在将nestjs的typescript与xpath模块一起使用。 但由于xpath模块类型不存在@types/xpath,我声明了自己的xpath类型,如下所示。 import * as xpath from 'xpath'; export class XmlParserService { private query(q: string): Array<Node | string> { return xpath.useNamespaces(this.namespa

我正在将nestjs的typescript与xpath模块一起使用。
但由于xpath模块类型不存在@types/xpath,我声明了自己的xpath类型,如下所示。

import * as xpath from 'xpath';

export class XmlParserService {

  private query(q: string): Array<Node | string> {
    return xpath.useNamespaces(this.namespaces)(q, this.parsedXml);
  }

我怎样才能为这个案子申报更多?感谢您阅读。

什么是“但是既然xpath模块类型没有声明或与其他模块类型不正确…”的意思?另外,您提到了
@types/xpath
,但我没有看到该软件包(
npm install@types/xpath
失败,它不是或)。
xpath
模块在
xpath/xpath.d.ts
中定义了自己的类型,我们可以这样做。@T.J.Crowder感谢您的回复。我的意思是我想为“xpath”模块声明我自己的类型。因此,我在node_modules文件夹外的本地目录中创建了./src/@types/xpath。但我认为我的类型不适合子函数或字段。我不知道如何声明“getAttribute或ownerDocument”。什么是“但是因为xpath模块类型不声明或与其他模块类型不正确…”的意思?另外,您提到了
@types/xpath
,但我没有看到该软件包(
npm install@types/xpath
失败,它不是或)。
xpath
模块在
xpath/xpath.d.ts
中定义了自己的类型,我们可以这样做。@T.J.Crowder感谢您的回复。我的意思是我想为“xpath”模块声明我自己的类型。因此,我在node_modules文件夹外的本地目录中创建了./src/@types/xpath。但我认为我的类型不适合子函数或字段。我不知道如何声明“getAttribute或ownerDocument”。
// ./src/@types/xpath/index.d.ts

declare module 'xpath' {
  type SelectedValue = Node | string;

  interface XPathSelect {
    (expression: string, node?: Node): Array<SelectedValue>;

    (expression: string, node: Node, single: true): SelectedValue | undefined;
  }

  export const select: XPathSelect;

  export function useNamespaces(namespaceMap: {
    [name: string]: string;
  }): XPathSelect;
}
  const currentNode = this.query(currentNodeQuery)[0];
  
  const idAttribute = currentNode.getAttribute('ID') ? 'ID' : 'Id';

  const ownerD = currentNode.ownerDocument