typehole icon indicating copy to clipboard operation
typehole copied to clipboard

Allow typeholes in other files

Open andrew-ironforge opened this issue 3 years ago • 5 comments

My biggest feature request would be to allow type holes to push output to other files. For example, I have a directory with the following structure:

Screen Shot 2021-05-17 at 2 55 13 PM

I would love to be able to create typeholes in each request that goes out to Quickbooks, and generate the types as the responses are received, and have those types go to internalTypes.ts instead of the file that the request was made in.

Loving the plugin so far! Really feels like it was developed by someone who understands that pain of not getting types from 3rd party APIs :) I could see this totally revolutionizing the creation of type files from existing Javascript libraries that have none...

andrew-ironforge avatar May 17 '21 19:05 andrew-ironforge

Really feels like it was developed by someone who understands that pain of not getting types from 3rd party APIs

You got that right 😄

I wonder if that feature would make sense as a workspace-level configuration.. I've been meaning to add some code to typehole to resolve interface references not in the same file as your typehole. That should be relatively easy to do. When I have that feature in place, you should at least be able to create a placeholder type first to fileA.ts

export type MyPlaceholder = any

and then create a typehole with that type, so fileB.ts

const someValue: MyPlaceholder = typehole.t(someValue)

and the interface should now update in fileA

rikukissa avatar May 18 '21 14:05 rikukissa

The approach I described in the previous comment should be possible with the 1.5.1 version. Give it a try and see if something like this would be enough for your use case 🙂

rikukissa avatar May 19 '21 17:05 rikukissa

Perfect! You're a legend.

andrew-ironforge avatar May 19 '21 21:05 andrew-ironforge

I'll try it now

andrew-ironforge avatar May 19 '21 21:05 andrew-ironforge

This feature would be awesome! I can confirm it works with relative imports, but not with aliased imports. It would be awesome if it supported alias imports as well :)

bombillazo avatar Jul 14 '23 04:07 bombillazo