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

Allow empty return statements on setters #9370

Closed
gjuchault opened this issue Jun 27, 2016 · 5 comments
Closed

Allow empty return statements on setters #9370

gjuchault opened this issue Jun 27, 2016 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@gjuchault
Copy link

TypeScript Version:
1.8.10

Code

class Foo {
  private _value: string = '';
  set value(newV: string): void {
    if (newV === this._value) {
      return;
    }

    // ...
  }
}

Expected behavior:

No errors.

Actual behavior:

A 'set' accessor cannot have a return type annotation..

Thanks :)

@aluanhaddad
Copy link
Contributor

Is the issue of the Void annotation, or the return statement I believe it's the former.

@gjuchault
Copy link
Author

The error is that TypeScript puts an error when there is a return statement on a setter; when it can makes sense to stop the setter becasue of validation or whatever

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jun 27, 2016
@RyanCavanaugh
Copy link
Member

The issue is the return type annotation, not the return statement. Expressionless return statements are legal. Return type annotations are not.

@gjuchault
Copy link
Author

@RyanCavanaugh Ok I'm not really sure what's the difference between the two. Is the : void non-sense on a setter ?

@RyanCavanaugh
Copy link
Member

Yes. The returned value of a setter is unobservable, so it doesn't make any sense to talk about its return type.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants