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

Union and intersection types with leading operator #12386

Merged
merged 4 commits into from
Nov 28, 2016
Merged

Union and intersection types with leading operator #12386

merged 4 commits into from
Nov 28, 2016

Conversation

mariusschulz
Copy link
Contributor

Fixes #12071

This pull request allows an ignored leading | or & in a type position to give developers more formatting freedom, e.g. like this:

type ReduxAction =
  | { type: "INCREMENT" }
  | { type: "DECREMENT" }
  | { type: "SET_VALUE", value: number };

@msftclas
Copy link

Hi @mariusschulz, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

@@ -2615,6 +2615,7 @@ namespace ts {
}

function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode {
parseOptional(operator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to also add SyntaxKind.BarToken and SyntaxKind.AmpersandToken to the isStartOfType function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Should I add another test for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea. For example, looking at where isStartOfType is called, we wouldn't properly handle a tuple type [| 0 | 1, | "foo" | "bar"] without this change, so maybe add a test for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I've updated both test files.

@ahejlsberg ahejlsberg merged commit c89b1eb into microsoft:master Nov 28, 2016
@ahejlsberg
Copy link
Member

@mariusschulz Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants