Skip to content

Way to tell TS that a JavaScript variable really is used somewhere #24790

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
mjbvz opened this issue Jun 8, 2018 · 6 comments
Closed

Way to tell TS that a JavaScript variable really is used somewhere #24790

mjbvz opened this issue Jun 8, 2018 · 6 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jun 8, 2018

From microsoft/vscode#51405

Feature request
For JavaScript, add a way to mark that a variable that appears unused is used somewhere. For example it may be used within a template that TS cannot analyze

Not sure if @ts-ignore should suppress unused too. It currently has no effect:

screen shot 2018-06-08 at 1 39 49 am

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jun 8, 2018
@ghost
Copy link

ghost commented Jun 8, 2018

@Fedoranimus A public method should never be marked as unused because unused testing isn't that smart. Similarly, something in global scope should never be marked as unused. We only mark things unused if they have a limited scope (or are private but that's not yet implemented for JS -- #14009). In a local scope I can't come up with an example other than eval where something that doesn't appear to be used, is.

@mhegazy mhegazy added this to the TypeScript 3.0 milestone Jun 8, 2018
@parzh
Copy link

parzh commented Jun 14, 2018

@Andy-MS What about AngularJS? There are cases when you have a variable in the controller, which is used indirectly in the view:

<!-- my-thing.component.html -->
<div>{{ $ctrl.property }}</div>
// my-thing.component.ts
class MyThing {
  public property = 42; // marked as unused, but is really used in the view
}

@ghost
Copy link

ghost commented Jun 14, 2018

@parzh Are you sure there isn't some other tool marking that as unused? TypeScript should never mark anything public as unused.

@parzh
Copy link

parzh commented Jun 14, 2018

@Andy-MS Oh, I actually didn't test it. Sorry for the confusion 😔
I just meant that there are cases where it might actually be useful to indicate explicitly that a locally scoped entity is used, even if it appears as unused. A lot of those are related to frameworks with view separated from controller (like AngularJS), but unfortunately I gave a bad example.

@ghost
Copy link

ghost commented Jun 14, 2018

As far as I can tell, there's no case where unused detection has a false positive (other than something erroneously marked private) -- let me know if you find a counterexample.

@mhegazy mhegazy removed this from the TypeScript 3.0 milestone Jun 14, 2018
@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jun 14, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants