-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor(typescript-estree): add type guards for typescript-estree #3078
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
Conversation
Thanks for the PR, @armano2! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Codecov Report
@@ Coverage Diff @@
## master #3078 +/- ##
=======================================
Coverage 92.83% 92.83%
=======================================
Files 314 314
Lines 10672 10675 +3
Branches 3027 3027
=======================================
+ Hits 9907 9910 +3
Misses 348 348
Partials 417 417
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Conflicts: packages/types/src/ts-estree.ts packages/typescript-estree/src/convert.ts
allowPattern?: boolean, | ||
): any { | ||
allowPattern?: P, | ||
): TSESTreeToTSNodeGuard<typeof node, P> { |
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.
I don't think this works the way you think it will - typescript will not parameterise the passed type of node
, meaning this type will be the same as TSESTreeToTSNodeGuard<TSNodeConvertable, P>
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.
yea i know that this type is not going to work, and it seem that there is no easy way around it, for now i just wanted to validate if we are missing anything in ast, best aproach i can think of is
private convertJSXTagName<T extends ts.JsxTagNameExpression>(
node: T,
parent: ts.Node,
): T extends ts.JsxTagNamePropertyAccess
? TSESTree.JSXMemberExpression
: T extends ts.ThisExpression | ts.Identifier
? TSESTree.JSXIdentifier
: TSESTree.JSXMemberExpression | TSESTree.JSXIdentifier;
private convertJSXTagName(
node: ts.JsxTagNameExpression,
parent: ts.Node,
): TSESTree.JSXMemberExpression | TSESTree.JSXIdentifier {
different function but same issue
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 PR aims to add proper types to conversion done by typescript-estree
this PR is currently blocked by #2933, #3081
changes from #3081 has been merged to this branch
detected issues with AST so far
LeftHandSideExpression
can be aAwaitExpression
#3083IntrinsicKeyword
is not defined in AST #3081PrivateIdentifier
is not defined in AST #2933TryStatement
finalizer can benull
#3083RegExpLiteral
value can benull
if regexp is invalid or unsupported by env #3083good example in this case can be any proposal that has not been accepted yet
eg. https://github.com/tc39/proposal-regexp-match-indices
JSXOpeningElement
attributes can be aJSXSpreadAttribute
#3083TSModuleDeclaration
body can beTSModuleDeclaration
#3083issues that need additional investigation