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

Typescript: Validate tuple type element positions #8828

Merged
merged 2 commits into from Nov 6, 2018

Conversation

Retsam
Copy link
Contributor

@Retsam Retsam commented Oct 8, 2018

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Adds additional validation to the parser functionality added by #8720 and #8805. Per this comment, adds a validation step to the parser which raises syntax errors if a rest param is not at the end of a tuple, or if a mandatory param follows an optional parameter. So the following snippets are correctly considered syntax errors:

const x: [number?, number]; // can't have mandatory member after optional member
const x: [...number[], string]; // rest element must be the last element of the tuple

…n tuple types

Adds a validation step to the parser which raises syntax errors if a rest param is not at the end of a tuple, or if a mandatory param follows an optional parameter
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 9, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9225/

@danez
Copy link
Member

danez commented Nov 6, 2018

Are they SyntaxErrors? If I try to parse these in the typescript playground, it all parses fine.

@Retsam
Copy link
Contributor Author

Retsam commented Nov 6, 2018

Yeah, they're supposed to be syntax errors:

screen shot 2018-11-06 at 2 10 31 am

@danez
Copy link
Member

danez commented Nov 6, 2018

Ah the typescript parser always tries to output something useful even if there are syntax errors in the code. 👍

@danez danez merged commit 2194842 into babel:master Nov 6, 2018
@danez
Copy link
Member

danez commented Nov 6, 2018

Thanks for your great contributions and helping to improve our typescript support. 🎉

@danez danez added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Nov 6, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants