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

AwaitExpression does not include ImportExpression as possible value of argument property #4877

Closed
3 tasks done
G-Rath opened this issue Apr 29, 2022 · 2 comments · Fixed by #4880
Closed
3 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Apr 29, 2022

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgQQMoBUD6A5A8gEQFFN0BNABUNQBo51Ur0oBTZuAXzgDMoIQ4A5AAEYATzDMAzgGMowMDAC0UgDbAAdjAD0AVxjAVkgQG4AsACgL0iOsnwAJsxjMoIDcwCS4aDFQQdUNJsALxwABQWcHDqEI4AXHQMGCzMAHTIAO4AhsAwhAAeYCySksA21BYAlAl2cuoA5nAAPtE6KipwwQB8iJFwwFzhMY6pWVD1OiDMmqliEp3BoWhYeEQkFFSpXpCwBUVSpTaVveZRUVpafewWfSwwAeqt7Wbm7MZAA

import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';

const determineImportSource = (
  node: TSESTree.AwaitExpression,
): string | null => {
  if (node.argument.type === AST_NODE_TYPES.ImportExpression) {
    //
  }

  return null;
};

Expected Result

No errors

Actual Result

An error from TypeScript:

This condition will always return 'false' since the types 'AST_NODE_TYPES.ArrayExpression | AST_NODE_TYPES.ArrayPattern | AST_NODE_TYPES.ArrowFunctionExpression | AST_NODE_TYPES.AwaitExpression | AST_NODE_TYPES.CallExpression | AST_NODE_TYPES.ClassExpression | ... 18 more ... | AST_NODE_TYPES.TSTypeAssertion' and 'AST_NODE_TYPES.ImportExpression' have no overlap

Additional Info

Here's an AST tree showing that it's possible to have an import expression as the argument of an await expression:

await import('@jest/globals');

image

https://astexplorer.net/#/gist/bd61e9f9222ff844ddbd1748895d8f8f/07c5c90e2933a965ef5329f4eb68588910343271

Versions

package version
@typescript-eslint/types 5.20.0
TypeScript 4.6.3
node v14.18.2
@G-Rath G-Rath added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for maintainers to take a look labels Apr 29, 2022
@G-Rath G-Rath changed the title AwaitExpression does not list ImportExpression as possible value of argument property AwaitExpression does not include ImportExpression as possible value of argument property Apr 29, 2022
@G-Rath
Copy link
Contributor Author

G-Rath commented Apr 29, 2022

(I don't think typescript-estree is actually the package this bug is in - I think it's in types; sorry 😅)

@bradzacher
Copy link
Member

ImportExpression should be added to LeftHandSideExpression.

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 29, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants