Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-unused-vars] nois assigned a value but only used as a type error when it has a same name in export statement#11322
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
Thanks for the PR,@nayounsang! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedJun 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify project configuration. |
is assigned a value but only used as a type error when it has a same name type alias declaration exporteis assigned a value but only used as a type error when it has a same namenx-cloudbot commentedJun 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
View yourCI Pipeline Execution ↗ for commita95d35e
☁️Nx Cloud last updated this comment at |
codecovbot commentedJun 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Pleaseupload reports for the commitfccdd43 to get more accurate results. Additional details and impacted files@@ Coverage Diff @@## main #11322 +/- ##======================================= Coverage 90.87% 90.88% ======================================= Files 505 505 Lines 51146 51157 +11 Branches 8424 8429 +5 =======================================+ Hits 46480 46494 +14+ Misses 4652 4649 -3 Partials 14 14
Flags with carried forward coverage won't be shown.Click here to find out more.
🚀 New features to boost your workflow:
|
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nayounsang commentedJun 27, 2025
Its a different issue:#8315, but we need to figure out if this is a workable solution. |
nayounsang commentedJun 27, 2025
Ah, it is different. should change validate logic. |
JoshuaKGoldberg commentedJun 30, 2025
@nayounsang apologies, I'm not following - are you suggesting we should or shouldn't review this PR? |
nayounsang commentedJun 30, 2025
@JoshuaKGoldberg The comments are my own monologue. I tend to take notes of everything and I just saw another issue that seemed related to this PR. After looking into it, it seems that even if this PR is resolved, there will be additional work needed to resolve the other issues. |
JoshuaKGoldberg left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🙌 Looks like a good start! I didn't review deeply because the.every line looks like it's either unnecessary or not fully tested. Which makes me suspect things might change up a bit. Could you please take a look?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
bradzacher left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
this is almost there -- but it misses this case:
constA=0;exportinterfaceA{}
| functionisMergedTypeDeclaration( | ||
| variable:Variable, | ||
| node:TSESTree.Node, | ||
| ):boolean{ | ||
| return( | ||
| node.type===AST_NODE_TYPES.TSTypeAliasDeclaration&& | ||
| variable.isTypeVariable&& | ||
| variable.isValueVariable | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
A better implementation to catch the interface case would leveragevariable.defs:
functionisMergedTypeDeclaration(variable:Variable,):boolean{return(variable.defs.length>1&&variable.isValueVariable&&variable.isTypeVariable&&variable.defs.some(d=>d.type===DefinitionType.Type));}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It can't cover this case:
// valid, but reportexportconstFoo=0;exporttypeFoo=typeofFoo;exportconstFoo=0;exportinterfaceFoo{}
What I meant was to check for theexport type Foo = ... statement. But in this case, it returns true if there are other type declarations besides theexport statement. This is becausenode exists within theexport statement when theisMergedTypeDeclaration is called.
So I've taken a different approach, can you please tell me if I'm going in the right direction?
Uh oh!
There was an error while loading.Please reload this page.
is assigned a value but only used as a type error when it has a same nameis assigned a value but only used as a type error when it has a same name in export statement
JoshuaKGoldberg left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM, thanks! I'll defer to@bradzacher as well on review. 👍
bradzacher left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There are the following 4 classes of cases here and we need to make sure we're reporting correctly on all of them.
////// case 1 -- both exported -- expected no reports///exportinterfaceFoo1{}exportconstFoo1=0;exporttypeBar1=0;exportconstBar1=0;exportconstFoo2=0;exportinterfaceFoo2{}exportconstBar2=0;exporttypeBar2=0;////// case 2 -- both exported via named export -- expected no reports///interfaceFoo7{}constFoo7=0;export{Foo7};typeBar7=0;constBar7=0;export{Bar7};constFoo8=0;interfaceFoo8{}export{Foo8};constBar8=0;typeBar8=0;export{Bar8};////// case 3 -- just value exported -- expected type is reported///interfaceFoo3{}exportconstFoo3=0;typeBar3=0;exportconstBar3=0;exportconstFoo4=0;interfaceFoo4{}exportconstBar4=0;typeBar4=0;////// case 4 -- just type exported -- expected value is reported///exportinterfaceFoo5{}constFoo5=0;exporttypeBar5=0;constBar5=0;constFoo6=0;exportinterfaceFoo6{}constBar6=0;exporttypeBar6=0;
The current implementation reports nothing on this code (which is technically half right heh).
Your current implementation:
- does not report on case 1 -- ✔️
- does not report on case 2 -- ✔️
- does not report on case 3 -- ❌
- reports on case 4 -- ✔️
So we'll need to handle this and add test cases
nayounsang commentedOct 24, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi.@bradzacher, There are some valid test cases I don't understand among the ones wrote before. This is added from#6873 |
bradzacher commentedNov 23, 2025
@nayounsang the test cases may have been added in the past, but that doesn't mean they're right! They were right in so far as they allowed the rule to understand when a multi-declaration variable was exported in its second declaration, but the result is wrong. interfaceFoo{// ^^^ Type Foo is unusedbar:string;}exportconstFoo='bar'; exportconstFoo='bar';interfaceFoo{// ^^^ Type Foo is unusedbar:string;} This is what we should expect to report for these two cases -- we should be able to understand that the variable's second declaration is unused. |

Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
is assigned a value but only used as a typeerror when it has a same name type alias declaration exported #10658Overview
Strict checks on exports with same type and variable name
isTypeVariable && isValueVariable.ClassName,TSEnumName,TSModuleName,ImportBindingandargumentsalso have same characteristicsPerform additional validating for abnormal cases
def.node.type !== AST_NODE_TYPES.TSTypeAliasDeclarationAdd test cases