typescript - 为什么 TypeScript 的 'declare global' 会导致 ESLint 错误?

标签 typescript eslint

所以,我在 .ts 文件的顶部有这个全局界面窗口:

declare global {
    interface Window {myOwnName: string;}
}

我需要它,因为我想为窗口属性分配新值。

代码有效,但 ESLint 给我这个错误:Parsing error, unexpected token.

Screenshot

有什么解决办法吗?在我的 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/

相关文章:

javascript - "Import in body of module; reorder to top import/first"跨多个文件

javascript - 在本地安装 ESLint 不起作用

javascript - 我可以在 JS 项目中使用 TS 库吗?

javascript - 如何使用 Joi 最新版本验证枚举字符串?

javascript - 为什么 typescript 不知道我检查了对象类型?

angular - 无法在 IE 中将 SVG 下载为 PNG

reactjs - JSX 的 ESLint 配置

node.js - 为什么 "npm run lint"指向父文件夹中的 .eslintrc 不是当前文件夹?

debugging - Chrome Typescript 调试引用错误 'this'

javascript - React 中的类分配