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

ASTPath<Function> is not assignable to parameter of type ASTNode #675

Open
danielo515 opened this issue Dec 1, 2021 · 0 comments
Open

Comments

@danielo515
Copy link

Hello, thanks for this great tool and its types.
Just found a situation that I don't understand fully. Seems that ASTPath is not compatible with ASTPath, which is weird because Function just extends ASTNode (as far as I know)

The whole error is like this:

  Overload 2 of 2, '(source: ASTNode | ASTNode[] | ASTPath<ASTNode> | ASTPath<ASTNode>[]): Collection<any>', gave the following error.
    Argument of type 'ASTPath<Function>' is not assignable to parameter of type 'ASTNode | ASTNode[] | ASTPath<ASTNode> | ASTPath<ASTNode>[]'.
      Type 'NodePath<Function, Function>' is not assignable to type 'ASTPath<ASTNode>'.
        Type 'Function' is not assignable to type 'ASTNode'.
          Property 'key' is missing in type 'Function' but required in type 'ClassPrivateMethod'.ts(2769)

The error is happening when I have a Function node that then I try to pass to JSCodeshift, which function signature is as you see above. If I just ignore the type error the code seems to work fine, but I am not sure if it is because I am only getting "compatible" nodes because Function is compatible with many subtypes.

Some example code may look like this:

j(file.source).find(j.Function).filter((path) => {
  j(path) //  <- here is where the error happens
})
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

No branches or pull requests

1 participant