Typing of object/array pattern components via ::
#1383
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #126 by implementing a long-sought syntax for typing individual object properties and array elements in left-hand-side patterns (including function arguments and assignment). Basically,
:: type
can come at the end of any existing object property or array element. For example:Why this notation?
name:: type: value
is ambiguous: it could be interpreted asname:: {type: value}
(typing as object). (I tried to include this as an option at first, but ran into this alternate parse.)name: value: type
is similarly ambiguous: it could be interpreted asname: {value: type}
(complex destructuring).I admit I still often type the wrong number of
:
s when writing examples, but I imagine we'll get used to it. (Also open to better proposals for notation.)I still need to write actual docs, but hopefully the example above and the tests give a reasonable idea.