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

No warnings about setting a deprecated property

Open maranomynet opened this issue 4 years ago • 11 comments

type T = {
	new?: string;
	/** @deprecated */
	old?: string;
};
const myT: T = { 
	// I'd expcect an ESLint warning here, but there is none
	old: 'value'
};

console.info(myT.old); // I only get a warning here

How it looks in VSCode: image

In fact VSCode doesn't warn (with a strike-through) about this either.

maranomynet avatar Oct 12 '20 12:10 maranomynet

This may actually be related to an issue with TypeScript itself. It would possibly be enough to wait for a bug fix and then make sure the latest version of TypeScript is used with this plugin. Fingers crossed.

https://github.com/microsoft/TypeScript/issues/39374

senekor avatar Aug 20 '21 08:08 senekor

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

gund avatar Dec 14 '21 15:12 gund

I seem to be having the same issue in v1.3.2 using TypeScript v4.5.4.

The plugin correctly picks up deprecated methods, but nothing seems to be reported for deprecated object properties.

stekern avatar Jan 13 '22 09:01 stekern

Actually now that I look at this - it makes total sense as the plugin is only reporting usages of deprecated code.

And in your case declaring an object with deprecated property is not usage it's declaration so it's not reported.

gund avatar Jan 13 '22 21:01 gund

Ah, okay. I was under the impression that the plugin would pick up everything annotated with @deprecated, be it methods or properties.

I do still think it would be beneficial to have this functionality for quickly and easily being made aware of usage of deprecated properties in our codebases. Is this functionality you'd consider in scope for this plugin?

stekern avatar Jan 14 '22 08:01 stekern

Yeah, that distinction does not make any sense to me.

When I declare an object of a certain type, I'm effectively using it's interface-/type-declaration.

For example: When I pass a deprecated prop to a React component, I'm in-place declaring the props object and get no warning that I'm using (in way of passing) a prop that the component's author explicitly flagged as @deprecated.

The way things are now, the only person to ever see a warning of a deprecated prop/option is the library author who flagged the prop themself, but is forced to use those props to maintain back-compatibility.

maranomynet avatar Jan 14 '22 16:01 maranomynet

Hmm this might actually be a valid use-case. I will reopen the issue to track it and PRs are welcome 😊

gund avatar Jan 14 '22 21:01 gund

This plugin does not detect deprecated properties when the definition is in another file.

nelson6e65 avatar May 23 '22 12:05 nelson6e65

I am wondering if there is any progress on this issue? We are trying to use this plugin in a large React project to deprecate props for certain components. Depending on the complexity, we may be interested in submitting a PR, but we would need some guidance

ghost avatar Oct 31 '22 18:10 ghost

I don't think there was any meaningful progress to fix this bug, so you are more then welcome to try and figure a fix for it in a PR. Unfortunately I could not be of help as I was not digging into eslint plugins (yet), maybe somebody else here can help but tbh I have no clue. One thing I can suggest as a helping tool is to use some TS AST explorer which could give you an idea how the fix could be implemented.

NOTE: I just had a quick look into the ast explorer and noticed that TS 4.8 also now tracks deprecated symbols in it's flags but it does not mark deprecated property declarations as deprecated as well. Type definition has deprecated flag (on PropertySignature symbol): image And property declaration (nor it's identifier) does not (as they have their own PropertyAssignment symbol): image And then property access is marked with deprecated flag (via PropertySignature symbol): image

So seems like TS does not link PropertyAssignment with PropertySignature symbols which basically looses deprecated flag on declared props.

gund avatar Oct 31 '22 23:10 gund