Skip to content

Use features from typescript 2.0 in ESTree#10305

Merged
vvakame merged 3 commits into
DefinitelyTyped:types-2.0from
rictic:estree
Aug 2, 2016
Merged

Use features from typescript 2.0 in ESTree#10305
vvakame merged 3 commits into
DefinitelyTyped:types-2.0from
rictic:estree

Conversation

@rictic

@rictic rictic commented Jul 27, 2016

Copy link
Copy Markdown
Contributor

case 2. Improvement to existing type definition.

  • documentation or source code reference which provides context for the suggested changes. url: https://github.com/estree/estree
    • it has been reviewed by a DefinitelyTyped member.

Uses discriminated union types to allow type narrowing based on string literal comparisons on the type field. This makes ESTree much more natural to use, with fewer casts needed.

For example:

let node: ESTree.Node;
let identifier: ESTree.Identifier;
if (node.type === 'Identifier') {
  identifier = node;  // succeeds with this PR!
}

@rictic rictic changed the title Use features from typescript 2.0 in estree Use features from typescript 2.0 in ESTree Jul 27, 2016
Enables narrowing of types based on doing string literal comparisons with
the type field. This makes estree much more natural to use, with fewer casts
needed.
@vvakame

vvakame commented Jul 28, 2016

Copy link
Copy Markdown
Member

@RReverser could you review this PR?

@RReverser

Copy link
Copy Markdown
Contributor

@rictic Thanks for working on this! One nit: can you please change newly created array types to match Array<...> style instead of ...[] (it helps for readability in case of more complex expressions, and also would be nice to preserve consistency).

Other than that, looks good!

@rictic

rictic commented Jul 29, 2016

Copy link
Copy Markdown
Contributor Author

Sure thing, moved them all to Array<T> style.

Thanks for the review!

Comment thread estree/index.d.ts Outdated
type: "ImportDeclaration";
specifiers: (ImportSpecifier|ImportDefaultSpecifier|ImportNamespaceSpecifier)[];
specifiers: Array<
ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please not break the line here? IMO it would look cleaner on the same one.

@rictic

rictic commented Jul 29, 2016

Copy link
Copy Markdown
Contributor Author

Sure thing, removed the line break.

@RReverser

Copy link
Copy Markdown
Contributor

Thanks! @vvakame might want you to squash commits, but LGTM.

@vvakame vvakame merged commit 9a600cd into DefinitelyTyped:types-2.0 Aug 2, 2016
@rictic rictic deleted the estree branch August 3, 2016 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants