fkling / astexplorer

A web tool to explore the ASTs generated by various parsers.
https://astexplorer.net/
MIT License
6.19k stars 737 forks source link

Typescript - does not support type declarations #590

Closed james-Infotrack closed 2 years ago

james-Infotrack commented 3 years ago

Describe the bug Syntax errors when defining a type

To Reproduce Steps to reproduce the behavior:

  1. Go to 'https://astexplorer.net/#/gist/42359365d6160cfab239ab069f88f7f6/bb924c4a84ff094ed5e4bad191eeb69db6db532f'

Expected behavior I'd love to be able to use it with type definitions inside the file

Screenshots image

Browser (please complete the following information):

astexplorer settings:

Additional context not sure if this is a PEBCAK error, but this basically kills my progress, so any help would be appreciated cheers

fkling commented 3 years ago

The problem is not with the typescript-eslint parser but with jscodeshift. You have to tell jscodeshift to use the typescript parser by adding

export const parser = 'typescript';

to the transform.

james-Infotrack commented 3 years ago

Thankyou for the update, I've added your comment to the top of my transform window but still get the same error

image

here is an updated snippet

this one has some react code, I was trying to modify

thanks again

fkling commented 3 years ago

Looks like it should be

export const parser = 'ts';

for Typescript or

export const parser = 'tsx';

if you also need JSX support.