-
Notifications
You must be signed in to change notification settings - Fork 29
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 void for destructuring forms and parameters #77
Comments
I think that would be a separate proposal from this one. |
Funnily enough, I was wondering whether to offer an alternative syntax that would go the opposite way and get rid of Might as well sketch it here:
Pros:
Cons:
|
I agree that if we're introducing |
I'm not sure const [{ x: { z } } delete, y delete] = ... Just knowing where to put the |
I am not too attached to
That sounds like a documentation problem. I would expect an API reference to say things like ‘this call returns an object which should be disposed’ or ‘this call returns a wrapper object containing properties X, Y and Z, which should be disposed’. Which they probably should do anyway: as #69 points out, handing out a reference to an object does not always confer ownership transfer, so (in the absence of language mechanisms preventing access to the disposal method) programmers will have to rely on documentation to know of which objects they should dispose, and of which they should not. I suppose a type checker might be able to validate disposal as well. † not equivalent if destructuring throws |
I like this idea. FWIW, nearly any non-identifier symbol could go here, though for the reasons above I agree that |
I'd prefer a keyword to a token like Also, the value of using a token like As for allowing
For parameters, indicating a |
Seems a non-issue in this particular case. Since disposal is only allowed for It is the current syntax which is more prone to ASI hazards, as a semicolon inserted between
The tilde character has a name, which can be searched for in those search engines that ignore punctuation marks (which is not all of them). Failing that, the reader may look up the construct by searching for material about |
This proposals adds
using const void =
to avoid creating a declaration. However other declaration forms such as destructuring would benefit from having an explicit "I'm ignoring this" variable.i.e. With array destructuring we currently have to either add dummy variables or use "holes", in both cases this can be confusing (in the former names can be fairly arbitrary or meaningless, and holes are often indicative of mistakes).
The forms I think that would be benefit from allowing
void
to indicate that we are intentionally discarding are:const [void, dat] = someArray;
const { x: void, y } = point;
array.filter((void, idx) => idx % 2 === 0);
The other declaration forms
let
/class
/function
/catch
either don't make sense to emit or can already be emitted.The text was updated successfully, but these errors were encountered: