Skip to content
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

Feature request: warn on unused result #17282

Closed
krisselden opened this issue Jul 19, 2017 · 6 comments
Closed

Feature request: warn on unused result #17282

krisselden opened this issue Jul 19, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@krisselden
Copy link

It can be easy to forget an await for a method returning Promise<void> and have your code appear to work.

I would be nice to have something like must_use in Rust or the __attribute__((warn_unused_result)) in C or @warn_unused_result in Swift.

@krisselden
Copy link
Author

This is my same struggle #13376

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 19, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

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

@mhegazy mhegazy closed this as completed Aug 17, 2017
@dannycochran
Copy link

dannycochran commented Sep 22, 2017

Can this be re-opened? I think having a "warn_on_unused" annotation is actually different than #13376.

There are plenty of non-async cases where you'd want to be warned about an unused result, for instance with redux.

const someActionCreator = (payload: string) => ({
  type: SOME_ACTION,
  payload
});

const someAction = () => (dispatch) => {
  // Compute the payload...
  const payload = 'foo.bar';
  // The correct way:
  // dispatch(someActionCreator(payload));

  // What can easily happen:
  someActionCreator(payload);
};

const onTouchTarget = () => this.props.dispatch(someAction());

This could be solved a number of ways, but a decorator seems pretty natural:

@warn_unused_result
const someActionCreator = (payload: string):  => ({
  type: SOME_ACTION,
  payload
});

@krisselden
Copy link
Author

krisselden commented Oct 6, 2017

this was mistakenly marked as a duplicate of #13376 that was the reason I had that motivated me opening this, but this feature is used in other languages for many reasons and is more generalized than #13376

@RyanCavanaugh
Copy link
Member

There's another issue I can't find at the moment that covers non-discardable function return values

@mhegazy
Copy link
Contributor

mhegazy commented Oct 9, 2017

tracked now by #8584

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants