question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error: 'xxx' is already defined (no-redeclare) when using typescript declaration merging

See original GitHub issue

Tell us about your environment

i am using vue-cli-plugin-electron-builder to build and bundle my electron app.

  • ESLint Version: 5.16.0
  • Node Version: 12.4.0
  • npm Version: 6.9.0 ( actually i use yarn 1.19.1 to manage my packages)

What parser (default, Babel-ESLint, etc.) are you using? -> means depends on, i will use -> to describe dependency chain @vue/cli-plugin-eslint 4.0.5 depends on eslint-loader 2.2.1 eslint-loader 2.2.1 invokes eslint, if i understand correctly.

Please show your full configuration:

Configuration
module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: ['plugin:vue/essential', '@vue/prettier', '@vue/typescript'],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  },
  parserOptions: {
    parser: '@typescript-eslint/parser',
  },
  overrides: [
    {
      files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
      env: {
        jest: true,
      },
    },
  ],
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import os from 'os';

export class NetExtra {
  static ipAddresses(
    family: NetExtra.IPAddressFamily = NetExtra.IPAddressFamily.ALL,
    includeInternal: boolean = true
  ): string[] {
    let ipAddresses: string[] = [];
    var ifaces = os.networkInterfaces();

    Object.keys(ifaces).forEach(function(ifname) {
      ifaces[ifname].forEach(function(iface) {
        if (!includeInternal && iface.internal !== false) {
          //skip over internal (i.e. 127.0.0.1)
          return;
        }
        if (family !== NetExtra.IPAddressFamily.ALL && iface.family != family) {
          return;
        }
        ipAddresses.push(iface.address);
      });
    });
    return ipAddresses;
  }
}

export namespace NetExtra {
  export enum IPAddressFamily {
    IPV4 = 'IPv4',
    IPV6 = 'IPv6',
    ALL = 'all',
  }
}

yarn electron:build --debug

What did you expect to happen?

eslint recognize typescript declaration merging and throw no error.

What actually happened? Please include the actual, raw output from ESLint.

error in ./src/commons/node/netExtra.ts

Module Error (from D:/Home/icenter-next/node_modules/eslint-loader/index.js): error: ‘NetExtra’ is already defined (no-redeclare) at src\commons\node\netExtra.ts:27:18: 25 | } 26 |

27 | export namespace NetExtra { | ^ 28 | export enum IPAddressFamily { 29 | IPV4 = ‘IPv4’, 30 | IPV6 = ‘IPv6’,

1 error found.

Are you willing to submit a pull request to fix this bug? possibly not due to not knowing eslint’s source codes and how it works

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Jan 8, 2020

Hi @bruceauyeung, thanks for the bug report!

I’m not sure if it’s possible to work around this issue in the core no-redeclare rule.

It might be good to open an issue in the typescript-eslint repo, maybe they’ll have some advice. It looks similar to typescript-eslint/typescript-eslint#60

1reaction
mdjermanoviccommented, Jan 9, 2020

@bruceauyeung by reading typescript-eslint/typescript-eslint#60 it also seems that the same kind of warnings reported by the no-redeclare are already reported by the TypeScript compiler, so the solution at the moment might be to turn off the rule in the configuration if it doesn’t add value for TS projects?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot redeclare block scoped variable - Stack Overflow
My editor shows this error when i have the typescript file and the javascript file open at the same time in the recent...
Read more >
eslint/eslint - Gitter
eslint-disable no-redeclare */ to avoid eslin errors, however I keep getting a eslint parse error : Parsing error: Identifier 'Platform' has already been ......
Read more >
protobuf.js
protobuf.js is a pure JavaScript implementation with TypeScript support for node.js and the browser. It's easy to use, blazingly fast and works out...
Read more >
parsing error: 'const declarations' require an initialization ...
However, when the code is parsed by a parser that does not reuse objects (like typescript-estree), the rule fires an error, because the...
Read more >
tslint-eslint-rules - npm
You want to code in TypeScript but miss all the rules available in ESLint? Now you can combine both worlds by using this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found