-
Notifications
You must be signed in to change notification settings - Fork 181
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
Signature of closure - return type should be mandatory (even if it is void
)
#2234
Comments
@yoav-steinberg - this means we will also have to add |
void
)
Hey, what's the reasoning behind this? I think that last language to adopt this approach was C++... |
Typescript works like this // not valid
let my_closure: ();
// valid
let my_closure: () => void; |
The reasoning is ergonomic/aesthetic in my mind. This |
We have decided to move along with Elad's suggested approach and expose |
Lets see how it feels to make signatures and closures require void while methods definitions keeping it optional:
|
@yoav-steinberg why can't we make Callback argument type annotation requires void (because it's a declaration), closure DOES NOT requires void (because it's a definition): let my_func = (callback: (x:num): void) => { ... }; Closure definitions DOES NOT require void: let my_func2 = (x: num) => { ... }; What do you think? |
Sure, lets do that! |
BTW, I think the interface declarations SHOULD HAVE interface IPointOfView {
computeTheMeaningOfLifeTheUniverseAndEverything(x: num): void;
// ...
} |
Revised reference given above comments:
|
Ack |
This allows using `void` as a builtin type and requires a return type for function types and interface methods Fixes #2234 ## Checklist - [X] Title matches [Winglang's style guide](https://docs.winglang.io/contributors/pull_requests#how-are-pull-request-titles-formatted) - [X] Description explains motivation and solution - [X] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
Congrats! 🚀 This was released in Wing 0.18.1. |
I tried this
Declare a variable for a closure that doesn't return a value (void).
I expected this:
To look like this:
Instead, this happened
Apparently this is the syntax:
Is there a workaround?
N/A
Component
Language Design
Wing Version
No response
Wing Console Version
No response
Node.js Version
No response
Platform(s)
No response
Anything else?
No response
Community Notes
The text was updated successfully, but these errors were encountered: