所以,我在 .ts 文件的顶部有这个全局界面窗口:
declare global {
interface Window {myOwnName: string;}
}
我需要它,因为我想为窗口属性分配新值。
代码有效,但 ESLint 给我这个错误:Parsing error, unexpected token.
有什么解决办法吗?在我的 eslint.json 配置中,我确实使用了这样的配置:
config = {
common: {
settings: {
'parser': '@typescript-eslint/parser',
'plugins': [
'@typescript-eslint',
'import'
],
'rules': {
'import/no-unresolved': 'error'
},
'import/resolver': {
'typescript': {},
'node': {
'moduleDirectory': [
'node_modules/',
'src/',
'proto/gen/'
]
}
}
}
}
}
感谢您的帮助!
最佳答案
您的配置文件可能没有被正确获取。 Eslint 配置文件必须命名为 .eslintrc
、.eslintrc.{js,json,yaml,yml}
之一。此外,您的配置对象不在 Eslint 预期的模式中。
关于typescript - 为什么 TypeScript 的 'declare global' 会导致 ESLint 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55792665/