Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Union and intersection types with leading operator#12386

Merged
ahejlsberg merged 4 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
mariusschulz:union-and-intersection-types-with-leading-operatorCopy head branch name to clipboard
Nov 28, 2016
Merged

Union and intersection types with leading operator#12386
ahejlsberg merged 4 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
mariusschulz:union-and-intersection-types-with-leading-operatorCopy head branch name to clipboard

Conversation

@mariusschulz

Copy link
Copy Markdown
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
Copy Markdown

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;

Comment thread src/compiler/parser.ts
}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.