Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [no-deprecated] Erroneous lint errors when @deprecated is applied to a nested namespace declaration #9902

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
4 tasks done
ashvinsrivatsa opened this issue Aug 29, 2024 · 6 comments
Labels
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 working as intended Issues that are closed as they are working as intended

Comments

@ashvinsrivatsa
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.5.4&fileType=.tsx&code=CYUwxgNghgTiAEA7KBbEBnADlMCCCAdAELwDeAsAFDzxgD2i6ALvAJ4Bc8zMAlogOYBuKgF8qVAPQAqKfAACoTHDBQmIYPCkSqoSLATI0WHPgIBhMlRr1GLAF6dufIaPGUb6OhBAEIdfgAUhEQErACUgkA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oBNFjpEZAIb5E3dFETRoHaJHBgAviEVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare namespace A.B {
  const y: string;
}

/** @deprecated */
declare namespace A.C {
  const z: string;
}

console.log(A.B.y);

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-deprecated": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

No lint errors on the line console.log(A.B.y), because none of the elements A, A.B, or A.B.y are marked @deprecated.

Actual Result

A @typescript-eslint/no-deprecated lint error appears on that line:

`A` is deprecated. 10:13 - 10:14

Additional Info

A real-world example of this is in the @types/chrome package, which provides typing for browser-specific APIs exposed by Chrome for use in Chrome Apps and Chrome Extensions. There are a bunch of specific APIs that are deprecated, such as:

/**
 * @deprecated Part of the deprecated Chrome Apps platform
 */
declare namespace chrome.socket {
  // ...
}

But this results in the linter raising a @typescript-eslint/no-deprecated at every usage site of chrome (not just chrome.socket - also other things like chrome.tabs, chrome.runtime, etc, which aren't deprecated).

@ashvinsrivatsa ashvinsrivatsa added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Aug 29, 2024
@Josh-Cena
Copy link
Member

Look at the editor hint:

A is deprecated.

So in fact, this JSDoc does indicate that A is deprecated. Changing it would require changing TS, not us.

@ashvinsrivatsa
Copy link
Author

ashvinsrivatsa commented Aug 29, 2024

Does it? See this code in the TypeScript playground:

namespace A.B {
  /** @deprecated */
  export const x = "x";
  export const y = "y"
}

/** @deprecated */
namespace A.C {
  export const z = "z";
}

console.log(A.B.x);
console.log(A.B.y);

On the two console.log lines, the editor applies the deprecation strikethrough only to the element x, not to either instance of the element A.

@Josh-Cena
Copy link
Member

The strikethrough seems to be applied inconsistently. Consider:

/** @deprecated */
namespace Foo.Bar {
  export const x = 1;
}

namespace Foo.Baz {
  export const x = 1;
}

Foo.Bar.x;
Foo striked through

OTOH, if you reorder Foo.Bar and Foo.Baz, you don't get any strikethroughs, on either Foo or Foo.Baz. Nevertheless, the quickinfo tells you that Foo indeed gets the @deprecated annotation, so it's considered deprecated when we query TS type info.

@bradzacher
Copy link
Member

Yeah I'd agree here.

Your code is really ambiguous.

/** @deprecated */
namespace Foo.Bar {}

What's meant to be deprecated here?
Is it Foo or Foo.Bar or both?
Is there another declaration of Foo that isn't deprecated? Is it supposed to be or is it not?

Add to that what Josh has found -- TS is even unsure what you meant!

So the recommendation is that you need to disambiguate your code.
EG by explicitly nesting the namespace and attaching the deprecation comment appropriately

namespace Foo {
  /** @deprecated */
  export namespace Bar {}
}

Or in the context of your example:

declare namespace A.B {
  const y: string;
}

declare namespace A {
  /** @deprecated */
  namespace C {
    const z: string;
  }
}

console.log(A.B.y); // no error
console.log(A.C.z); // errors

playground

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2024
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Aug 29, 2024
@Josh-Cena
Copy link
Member

Josh-Cena commented Aug 29, 2024

In this case it's from @types/chrome, so I'd appreciate how hard it would be to fix... Could be helped by an ignore option though, like #9899.

@bradzacher
Copy link
Member

Filed microsoft/TypeScript#59792 -- we'll see what they say.
Clarification on the "correct" disambiguation would be good.

@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 Sep 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
@github-staff github-staff deleted a comment from telfaw Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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 working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

3 participants