Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-shadowed-variable: issue with interface extension #3088

Closed
sinedied opened this issue Aug 1, 2017 · 3 comments · Fixed by #3387
Closed

no-shadowed-variable: issue with interface extension #3088

sinedied opened this issue Aug 1, 2017 · 3 comments · Fixed by #3387

Comments

@sinedied
Copy link

sinedied commented Aug 1, 2017

Bug Report

  • TSLint version: 5.5.0
  • TypeScript version: 2.4.2
  • Running TSLint via: angular-cli

TypeScript code being linted

import { RequestOptionsArgs } from '@angular/http';

export enum HttpCachePolicy {
  Never = <any>false,
  Always = <any>true,
  Update = <any>'update'
}

// RequestOptionArgs is declared in a re-exported module, so we have to extend the original module to make it work
// properly (see  https://github.com/Microsoft/TypeScript/issues/13897)
declare module '@angular/http/src/interfaces' {

  // Use this interface to extend requests options if needed
  export interface RequestOptionsArgs {
    cache?: boolean|HttpCachePolicy;
    skipErrorHandler?: boolean;
  }

}

with tslint.json configuration:

{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "arrow-return-shorthand": true,
    "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "import-blacklist": [
      true,
      "rxjs"
    ],
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "jsdoc-format": true,
    "label-position": true,
    "max-line-length": [
      true,
      120
    ],
    "member-access": false,
    "member-ordering": [
      true,
      "public-before-private",
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-variable": [
      true,
      "check-parameters"
    ],
    "no-duplicate-super": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": [
      true,
      "ignore-params"
    ],
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unnecessary-initializer": true,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef": [
      true,
      "parameter",
      "property-declaration"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "typeof-compare": true,
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],
    "directive-selector": [
      true,
      "attribute",
      "app",
      "camelCase"
    ],
    "component-selector": [
      true,
      "element",
      "app",
      "kebab-case"
    ],
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-input-rename": true,
    "no-output-rename": true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "no-access-missing-member": true,
    "templates-use-public": true,
    "invoke-injectable": true
  }
}

Actual behavior

This error is reported:

ERROR: /Users/noda/github/generator-ngx-app/sample/src/app/core/http/request-options-args.ts[20, 20]: Shadowed name: 'RequestOptionsArgs'

Expected behavior

No error should be reported here as the intent is to extend the existing interface, this is not a case of shadowed variable.

@adidahiya
Copy link
Contributor

I guess you're right, but why do you need to import RequestOptionsArgs in that file? It looks unused (would be flagged by tsc --noUnusedLocals).

@sinedied
Copy link
Author

sinedied commented Aug 2, 2017

This is maybe a TypeScript issue, but if I remove the import the interface extension does not work well, maybe because it depends of the load order. Maybe it's fixed in latest TypeScript versions, I'll make some tests.

Anyway the TS compiler does not flag it as unused.

@adidahiya
Copy link
Contributor

Ok, thanks for the response. We'd accept a PR that makes the rule ignore shadowed types inside ambient declaration blocks (declare module ...).

@ajafff ajafff self-assigned this Oct 23, 2017
adidahiya pushed a commit that referenced this issue Nov 28, 2017
…3387)

[bugfix] `no-shadowed-variable` now excludes declaration files and ambient modules
Fixes: #3088
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this issue Apr 9, 2018
…alantir#3387)

[bugfix] `no-shadowed-variable` now excludes declaration files and ambient modules
Fixes: palantir#3088
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants