-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Conversation
@@ -18,6 +19,7 @@ | |||
}, | |||
"license": "BSD-2-Clause", | |||
"dependencies": { | |||
"@types/estree": "0.0.34", |
There was a problem hiding this comment.
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);
}
}
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. |
That's understandable. It's not much less convenient to have the types in DefinitelyTyped instead. Thanks for the quick review :) |
@rictic So are you going to add it into DefinitelyTyped? |
@rictic Could you upload this to DefinitelyTyped? That will save many people. |
No description provided.