I do a refactory of a large project. I split large modules into smaller ones.
So when i move imports to a new module i want to remove unused imports.
This can not be done easily as i click in context menu "Find All references" it shows all the references in the current project - "it is very unuseful i admit".
_So, if it is by design, then this problem can be ameliorated by showing unused imports as grayed._
@BBGONE have you tried to use tslint and corresponding editor plugin? It can highlight unused imports.
@s-panferov Thanks, i did not try, yet. It will be very helpful in my case.
I think this would be solved if noUnusedParameters
and noUnusedLocals
would be shown as warnings, not as errors. See for example https://github.com/Microsoft/TypeScript/issues/13408.
in fact _noUnusedParameters_ and _noUnusedLocals_ behave very rough.
For example i have a code like this:
obj.addOnPropertyChange("*", function (s, a) {
if (props.indexOf(a.property) > -1) {
fn_onChange(a.property);
}
}, self.uniqueID);
where the s parameter is not used, but it's not an error. I can not remove it because it's the function's signature and is required, and it's not the last parameter which i can not simply ommit.
Another problem when i declare an abstract class which members should be overriden. It's member functions have some parameters which is not used, but are used when overriden.
So these compiler options should account for the above situations.
Regarding:
obj.addOnPropertyChange("*", function (s, a) {
if (props.indexOf(a.property) > -1) {
fn_onChange(a.property);
}
}, self.uniqueID);
Yeah, that's why it should be warning and not an error. (And maybe not even a warning in this case.)
By the way you can "fix" this by writing _s
instead of s
. Now TypeScript will just ignore it.
Though, version 1.19 underlines unused symbols in the imports now I wish the entire import was greyed out similar to other IDEs. That would make such imports easier to spot.
@andy-ms this is related to the non-error suggestions feature.
any progress on this?
I am looking forward this feature too
now, for me it's all ok when unused imports is an error. If there's an error, i just remove the unused import.
We would rather have it as a grayed warning. Errors break the build.
Also waiting for this feature!
Also would like to see this.
+1
Just merged in support for this into VS Code: https://github.com/Microsoft/vscode/issues/15710
Should be in tomorrows VS Code insiders. It is controlled by the settings:
"javascript.showUnused.enabled": true,
"typescript.showUnused.enabled": true,
@mjbvz when it will be published for all?
Most helpful comment
Just merged in support for this into VS Code: https://github.com/Microsoft/vscode/issues/15710
Should be in tomorrows VS Code insiders. It is controlled by the settings: