-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Suggestion: Allowing leading pipe in union type declarations #12071
Labels
Fixed
A PR has been merged for this issue
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
Comments
DanielRosenwasser
added
Suggestion
An idea for TypeScript
In Discussion
Not yet reached consensus
labels
Nov 6, 2016
RyanCavanaugh
added
Help Wanted
You can do this
and removed
In Discussion
Not yet reached consensus
labels
Nov 15, 2016
Accepting PRs to allow one leading ignored |
@RyanCavanaugh If I'm not mistaken, parsing a leading function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode {
+ parseOptional(operator);
let type = parseConstituentType();
if (token() === operator) {
const types = createNodeArray<TypeNode>([type], type.pos);
while (parseOptional(operator)) {
types.push(parseConstituentType());
}
types.end = getNodeEnd();
const node = <UnionOrIntersectionTypeNode>createNode(kind, type.pos);
node.types = types;
type = finishNode(node);
}
return type;
} Where exactly would an accompanying test go? |
@mariusschulz you can drop a new file in |
@RyanCavanaugh Thanks! I've sent a pull request: #12386 |
5 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Fixed
A PR has been merged for this issue
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Currently, because of the leading
|
symbol , the following code is invalid TypeScript:I suggest we relax the syntax such that a single leading pipe symbol is allowed (but not required) in a union type declaration. Flow and F#, for example, both allow this syntax.
This change is backwards-compatible and gives developers a little more code formatting freedom.
The text was updated successfully, but these errors were encountered: