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

Add typings for typescript users. #321

Closed
wants to merge 1 commit into from
Closed

Conversation

rictic
Copy link

@rictic rictic commented Feb 22, 2017

No description provided.

@jsf-clabot
Copy link

jsf-clabot commented Feb 22, 2017

CLA assistant check
All committers have signed the CLA.

@@ -18,6 +19,7 @@
},
"license": "BSD-2-Clause",
"dependencies": {
"@types/estree": "0.0.34",
Copy link
Author

Choose a reason for hiding this comment

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

This may be slightly unexpected, but it's a small dependency (28K on disk) and it includes all of the info needed to understand estree in typescript.

These estree typings combine well with typescript's type system, allowing for some really neat stuff. e.g. there's automatic type inference based on comparison with the type property. So typescript can type check this code correctly without any type annotations:

const program = espree.parse('foo');
const firstStatement = program.body[0];
if (firstStatement && firstStatement.type === 'ExpressionStatement') {
  const expression = firstStatement.expression;
  if (expression.type === 'Identifier') {
    console.log(expression.name);
    // typescript warns here, because an estree Identifier doesn't have a nom property
    console.log(expression.nom); 
  }
}

@nzakas
Copy link
Member

nzakas commented Feb 23, 2017

I'm sorry, we aren't going to be including TypeScript definitions in the package. We just don't have the resources to maintain this on an ongoing basis, and we don't want to get into a situation where we then need to support type definitions for multiple dialects.

@rictic
Copy link
Author

rictic commented Feb 23, 2017

That's understandable. It's not much less convenient to have the types in DefinitelyTyped instead. Thanks for the quick review :)

@rictic rictic closed this Feb 23, 2017
@rictic rictic deleted the typings branch February 23, 2017 20:58
@JounQin
Copy link

JounQin commented Jul 29, 2019

@rictic So are you going to add it into DefinitelyTyped?

@linonetwo
Copy link

@rictic Could you upload this to DefinitelyTyped? That will save many people.

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.

5 participants