benjamn / benjamn/ast-types

Wrong structure of TSFunctionType node

Open
#940 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
194
Avg merge
22h 43m
Merged PRs (30d)
10

Description

Given the following code:
```
export const FooFoo = buildFoo('Foo') as unknown as (foo: any) => Foo | FooLegacy;
```

What ast-explorer shows is that the `TSUnionType` node is on the `returnType` attribute of the `TSFunctionType` node:
![image](https://github.com/benjamn/ast-types/assets/2238944/ad0e00df-0ec3-4002-83a8-bd029a0fb395)

However when using jscodeshift with recast/ast-types it's being parsed as the following:
jscodeshiftCodemod ts — pineapple 2023-07-06 15-43-42

instead of being on the `tsFunctionTypeNode.returnType.typeAnnotation` attribute, it's actually structured as `tsFunctionTypeNode.typeAnnotation.typeAnnotation`

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the reported TypeScript snippet in ast-explorer and through jscodeshift with recast/ast-types. Compare the TSFunctionType structure, especially returnType and typeAnnotation, and inspect the parser and AST node definitions involved. Done means both paths expose the TSUnionType under the same expected attribute.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.