Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does TypeScript's 'declare global' cause ESLint error?

So, I have this global interface Window at the top of the .ts file:

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

I need this because I want to assign new values to the window property.

Code works, but ESLint gives me this error: Parsing error, unexpected token.

Screenshot

Any ideas how to fix this? In my eslint.json config I do use such configuration:

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/'
                    ]
                }
            }
        }
    }
}

Thanks for help!

like image 712
Nikita Shchypyplov Avatar asked Apr 22 '19 10:04

Nikita Shchypyplov


1 Answers

Your config file is probably not being picked up correctly. Eslint config files must be named as one of .eslintrc, .eslintrc.{js,json,yaml,yml}. Also your config object is not in the schema expected by Eslint.

like image 52
golopot Avatar answered Nov 04 '22 22:11

golopot