Search code examples
javascriptnode.jsreactjstypescript

ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace


I'm receiving the following error running npm start:

ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace

    namespace InternalThings {...}

I tried to research this but it's very confusing.

Why does this is happening? How to fix it?

I tried to put some flags on my tsconfig.json but so far no success;


Solution

  • This is a lint error, caused by this lint rule: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-namespace.mdx

    If you find the rule useful and want to keep it, then you'll need to modify your code to use import and export instead of namespace. See the documentation of the rule for what counts as a fix.

    If you like the rule, but want to disable the rule for this line, add the following just above it:

    // eslint-disable-next-line @typescript-eslint/no-namespace
    

    If you don't like the rule and want to disable it entirely, then edit your .eslintrc file to have the following line:

    rules: {
      "@typescript-eslint/no-namespace": "off"
    }