8000 [no-unsafe-member-access] Not allowing "interface X extends" for a type in a nested namespace · Issue #3292 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

[no-unsafe-member-access] Not allowing "interface X extends" for a type in a nested namespace #3292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
cbdeveloper opened this issue Apr 16, 2021 · 3 comments · Fixed by #9478
Closed
3 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@cbdeveloper
Copy link
cbdeveloper commented Apr 16, 2021
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

Playground

I wasn't able to build a repro for this issue, but it really seems like a bug.

I have the following d.ts file on my project (I'm using namespaces to organize my types).

XXX.d.ts

declare namespace XXX {

  interface Temp1 {
    foo: "bar"
  }

  namespace WWW {

    interface Temp2 {
      foo: "bar"
    }

  }

}

So the XXX is ambient and the WWW namespace is nested within it.

I need to extend the Temp2 interface, that lives on the nested WWW namespace.

So I did this:

interface Test2 extends XXX.WWW.Temp2 {}

And I got this error:

image

So I thought: "eslint might not be detecting the XXX namespace". But that is not true, as you can see that the following code works fine when extending Temp1 which is a direct member of the XXX namespace.

interface Test1 extends XXX.Temp1 {}

image

And what is even weirder is that if I use an intermediate AUX type, it works fine:

type AUX = XXX.WWW.Temp2;
interface Test2A extends AUX {}

image

Expected Result

There shouldn't be any errors when extending a nested namespace.

interface Test2 extends XXX.WWW.Temp2 {}

Actual Result

The @typescript-eslint/no-unsafe-member-access is being triggered.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.22.0
@typescript-eslint/parser 4.22.0
TypeScript 4.2.4
ESLint 7.24.0
node 10.19.0

.eslintrc.js

const config = {

  root: true,
  

  env: {
    browser : true,
    commonjs: true,
    es2017: true,
    node: true
  },
  parser: "@typescript-eslint/parser",
  ignorePatterns: [
    ".eslintrc.js",
    "webpack.*.ts",
    "babel.config.*.js"
  ],
  parserOptions: {
    project: "./tsconfig.json",
    sourceType: "module",
  },

  globals: {
    gtag: "readonly"
  },

  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:react-hooks/recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],

  plugins:[
    "react",
    "react-hooks",
    "@typescript-eslint"
  ],

  rules: {
    "semi": "error",
    "react/prop-types": "off",
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn",
    "@typescript-eslint/no-unused-vars": ["warn", {"args":"none"}],
    "@typescript-eslint/no-empty-interface": "off",
    "@typescript-eslint/prefer-regexp-exec": "off",
    "@typescript-eslint/require-await": "off"
  },
  
  settings: {
    "react": {
      version: "detect"
    }
  },

  overrides: [
    { 
      files: ["*.js"],
      rules: {
        "@typescript-eslint/no-var-requires": 0
      }
    }
  ]
};

module.exports = config;

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "types": ["node"],
    "baseUrl": ".",
    "paths": {
      "@app/*": ["./app/*"],
      "@lib/*": ["./lib/*"]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

@cbdeveloper cbdeveloper added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 16, 2021
@bradzacher
Copy link
Member

Related to #2740 - the fix applied there only handles one level of namespacing.
It's not common to nest namespaces more than 1 deep and use them in an extends clause.

@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Apr 19, 2021
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
Copy link

Uh oh! @cbdeveloper, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

@JoshuaKGoldberg
Copy link
Member
JoshuaKGoldberg commented Dec 17, 2023

Aside: this ☝️ bot comment is not spam. Everything it says is true and accurate. Please add appropriate alt text to any image you post, so that it's usable both for GitHub searches and folks who can't visually perceive it. 🙂

(context: it was marked as spam and I don't know how or why)

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jul 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0