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

Parentheses in type literals #914

Merged
merged 8 commits into from
Oct 20, 2014
Merged

Parentheses in type literals #914

merged 8 commits into from
Oct 20, 2014

Conversation

ahejlsberg
Copy link
Member

This change adds support for parentheses in type literals. For example:

var a: (string | number)[];
var b: (() => string)[];
var b: (() => string) | (() => number);
var c: ((() => string) | (() => number))[];

There is a formal definition of the grammar in the updated language specification, but basically the grammar requires parentheses in the following cases:

  • When function and constructor types are used in union types.
  • When union, function, and constructor types are used in array types.

Similar to expressions, parentheses may be used for clarity in other contexts even if they aren't necessary.

@CyrusNajmabadi
Copy link
Contributor

👍 Very nice. Looks clean and simple. I wish the CR for the spec update parts were easier to understand (but that's not under your control).

ahejlsberg added a commit that referenced this pull request Oct 20, 2014
@ahejlsberg ahejlsberg merged commit 152a940 into master Oct 20, 2014
@ahejlsberg ahejlsberg deleted the parensInTypes branch October 20, 2014 16:43
@DanielRosenwasser DanielRosenwasser mentioned this pull request Nov 4, 2014
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
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.

None yet

2 participants