eslint-plugin-deprecation icon indicating copy to clipboard operation
eslint-plugin-deprecation copied to clipboard

False Positive error when extending a deprecated method

Open dkimmich-onventis opened this issue 3 years ago • 13 comments

In the following scenario, when calling method() on an instance of the New class, the plugin should not report an error, but it does:

class Old {
  /** @deprecated */
  method(): void {
  }
}

class New extends Old {
  method(): void {
  }
}

new Old().method(); // should throw an error -> everything fine
new New().method(); // should not throw an error -> still throws an error

dkimmich-onventis avatar May 14 '21 08:05 dkimmich-onventis

I'm facing a similar issue where a function has multiple signatures, one of which is deprecated and even if I use the new calling convention I get a warning.

// From "fast-check" package

/**
 * @deprecated
 */
declare function lorem(maxWordsCount: number, sentencesMode: boolean): Arbitrary<string>;

declare function lorem(constraints: LoremConstraints): Arbitrary<string>;
import * as fc from "fast-check"

fc.lorem({ maxCount: 5 }) // <- warning issued here.

wereHamster avatar Jul 28 '21 05:07 wereHamster

@wereHamster I cannot reproduce this. For me, everything works fine:

/**
 * @deprecated
 */
declare function lorem(maxWordsCount: number, sentencesMode: boolean): string;
declare function lorem(constraints: { maxCount: number }): string;

lorem({ maxCount: 5 }); // -> no warning
lorem(5, false); // -> warning

Are you sure the lint error is reported by this package? I ran into a very similar issue using eslint-plugin-import https://github.com/import-js/eslint-plugin-import/issues/1532, which made me switch to this package.

dkimmich-onventis avatar Jul 28 '21 07:07 dkimmich-onventis

Both vscode and eslint cli report the warning:

image

I'm using the latest eslint and related packages (@typescript-eslint/* etc).

wereHamster avatar Jul 28 '21 08:07 wereHamster

We just released an updated with latest deps in v1.3.1 maybe you can try it out and see if this is still an issue?

gund avatar Dec 14 '21 16:12 gund

@Delagen unfortunately this is still an issue with the latest version.

dkimmich-onventis avatar Dec 15 '21 07:12 dkimmich-onventis

@json-derulo tried to fix this in https://github.com/Delagen/eslint-plugin-deprecation/pull/1, but I reverted it by his opinion about false positives https://github.com/Delagen/eslint-plugin-deprecation/pull/1#issuecomment-989909128. May be someone try to fix this? PR are welcome

Delagen avatar Dec 15 '21 08:12 Delagen

Yes I tried to fix it, but it turned out to be way more complex than expected. I did not succeed to fix this.

What I observed is that the unit tests don't cover every case. I've updated them while trying to fix the issue, opened #42 to add them.

json-derulo avatar Dec 15 '21 08:12 json-derulo

I've been able to narrow down the issue. With TypeScript 4.1 it works, since TypeScript 4.2 the described case is broken. Maybe due to their new feature abstract Construct Signatures. But had no luck so far finding out what needs to be changed in this repo.

json-derulo avatar Dec 15 '21 18:12 json-derulo

Any updates on this? Facing same exact issue.

Angular 12 "@typescript-eslint/eslint-plugin": "^5.12.0", "eslint": "^7.32.0", "eslint-plugin-deprecation": "^1.3.2", "typescript": "^4.3.5",

polklabs avatar Feb 18 '22 17:02 polklabs