mardi 4 février 2020

Is there an API to make programatic TypeScript reflection?

I'd like to extract metadata related to Props objects. For the example below I might get something as simple as this:

{
  suffix: 'string',
  count: 'number',
  increment: 'function'
}

I realize that this is a complex task, as each of those props could be union types for example. But I'd like a starting point, and I can live with not capturing the entire type info into this reflection.

The manual approach would be to use a parser to get the AST of that Props object, but this involves a serious degree of work because any of those types could reference types from other files, so I'd have to write a script that essentially knows how to follow imports, and possibly other complications I haven't thought of yet.

Before I embark into such a complicated task, I was wondering if there is already some API to do this, whether TypeScript official or made and used by some other popular tool. Code editor plugins must get this information somehow to provide autocomplete.

enter image description here

So far I found this project: https://github.com/plumier/tinspector – But it doesn't seem very used and it doesn't seem to follow imports either, which is my main concern.

Thanks!





Aucun commentaire:

Enregistrer un commentaire