benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
5.01k stars 350 forks source link

recast.parse returns any #692

Open realdoug opened 4 years ago

realdoug commented 4 years ago

I'd like to use this library via Typescript but the top-level parse function returns any, meaning I need to do at least one cast to start using the type system. What is the suggested way of getting typed values out of recast?

Thanks

eventualbuddha commented 4 years ago

The types could certainly be improved. Personally, I would try not to use any at all. The type of copy should probably be copy<T>(node: T): T at minimum, perhaps even with a type constraint T extends … to restrict it to some sort of basic Node type. Part of the problem is that recast supports lots of different parsers with slightly different AST formats.