英文:
TypeScript .entries() does not exist on type 'DOMTokenList'
问题
我正在使用vue3,vite和ts。我对DOMTokenList有一个问题。我想使用.entries()
方法,但ts说属性 'entries' 在类型 '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)版本,但没有得到任何结果。我该如何解决这个问题?谢谢建议。
英文:
I am using vue3, vite and ts. I have a porblem with DOMTokenList. I want to use .entries()
method but ts says Property 'entries' does not exist on type 'DOMTokenList'
This is my tsconfig file
{
"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"
}
]
}
Also I am using .enties()
function to extend DOMTokenList
DOMTokenList.prototype.removeStartWith = function(prefix:string){
this.remove(...Array.from(this.entries()).map(([,c]) => c).filter(c => c.startsWith(prefix)))
}
I tried previous ECMA (ES2019) versions but I didn't get any result. How can I solve that? Thanks for suggestions.
答案1
得分: 1
根据 @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"
}
]
}
英文:
Based on @jcalz comment, I added the "DOM.Iterable"
lib. And problem solved. I was thinking that the "DOM"
lib contains "Iterable". But it didn't contain.
{
"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"
}
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论