javascript TypeScript .entries()在类型“DOMTokenList”上不存在

5jvtdoz2  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(133)

我使用vue3,vite和ts。我有一个问题与DOMTokenList。我想使用.entries()方法,但ts显示为Property 'entries' does not exist on type 'DOMTokenList'
这是我的tsconfig文件

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "main.d.ts"],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "typeRoots": ["./node_modules/@types", "src/core/types"],
    "ignoreDeprecations": "5.0",
    "lib":["DOM","ESNext"]
  },
  "references": [
    {
      "path": "./tsconfig.node.json"
    }
  ]
}

另外,我使用.enties()函数来扩展DOMTokenList

DOMTokenList.prototype.removeStartWith = function(prefix:string){
    this.remove(...Array.from(this.entries()).map(([,c]) => c).filter(c => c.startsWith(prefix)))
}

我尝试了以前的ECMA(ES2019)版本,但没有得到任何结果。我该怎么解决呢?谢谢你的建议。

hgc7kmma

hgc7kmma1#

基于@jcalz注解,我添加了"DOM.Iterable"库。问题解决了我在想"DOM"库包含“Iterable”。但里面没有。

{
  "extends": "@vue/tsconfig/tsconfig.web.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "main.d.ts"],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "typeRoots": ["./node_modules/@types", "src/core/types"],
    "ignoreDeprecations": "5.0",
    "lib":["DOM","DOM.Iterable","ESNext"]
  },
  "references": [
    {
      "path": "./tsconfig.node.json"
    }
  ]
}

相关问题