ast-types icon indicating copy to clipboard operation
ast-types copied to clipboard

Wrong structure of TSFunctionType node

Open shogunsea opened this issue 1 year ago • 1 comments

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

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

shogunsea avatar Jul 06 '23 22:07 shogunsea

additionally, it seems TSFunctionTypeBuilder only takes single parameters argument, so it seems it's impossible to annotate the return type?
https://github.com/benjamn/ast-types/blob/6e4d91213c27b6ba76a747c45200aa0e8498b176/src/gen/builders.ts#L3248

shogunsea avatar Jul 06 '23 22:07 shogunsea