ASTPath<Function> is not assignable to parameter of type ASTNode
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 194
- Avg merge
- 22h 43m
- Merged PRs (30d)
- 10
Description
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 | ASTPath[]): Collection', gave the following error.
Argument of type 'ASTPath' is not assignable to parameter of type 'ASTNode | ASTNode[] | ASTPath | ASTPath[]'.
Type 'NodePath' is not assignable to type 'ASTPath'.
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:
```ts
j(file.source).find(j.Function).filter((path) => {
j(path) // <- here is where the error happens
})
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the ASTPath and collection typings involved in j.Function and j(path), then reproduce the provided TypeScript example to isolate the assignability mismatch. Done means the example type-checks without an unsafe cast, with coverage for passing an ASTPath to the collection entry point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100