WIP/RFC - first jab at implementing Flow-style annotations-in-comments #13390
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.
See #9694 .
My workplace, and many community projects, are aware of the analysis capabilities of Typescript, but shy away from having a build step added to projects that are currently written in raw JS. This makes Typescript a non-starter. Facebook's Flow has a nifty feature whereby annotations can be added as comments inline in JS, meaning no build step is required. E.g.
This seems to have seen wide approval and support from the Flow community.
This PR implements this feature in Typescript. It's clearly uglier that direct annotations, but it's a much more succinct way of adding Typescript annotations to valid Javascript than JSDoc.
Two constructs are supported.
/*: typename*/
is interpreted as: typename
, as in the first two examples above./* :: statements; ... */
is interpreted asstatements; ...
.It may also be worth considering
/* <parameter> */ -> <parameter>
to allow manually specifying generic parameters where elision is not possible. This would also allow angle bracket type assertions. Note that this would be a convenience extension - as currently implemented, this is already possible with/* :: <parameter> */
This is a first go to see how easy this was to implement - I am aware that the CLA needs to be signed, test cases need to be written, that the issue needs to be tagged as needing a proposal (and that there is no guarantee this will happen!), and said proposal needs to be written and accepted, and that this is a language change and will thus be either highly contentious or rejected outright.