-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for imported types #3
Comments
This has been in my mind for quite some time, I haven't decided on whether to spin up the TypeScript language server, or just manually hard-code support for e.g. imports. I guess the latter is a good first step though. I'll have a look at this. |
Just did my first test of the functionality (via source types
Output
I would expect either the extends to be preserved, eg: Since the "extends X" is dropped and the parent's fields are not included, the output is invalid for our purposes. Notes
|
If this was supported it would be very useful. Then an already existing project with types spread all over could be used. |
So, a long time later, sorry for that; This is a pretty complicated topic. For this to work as expected, you'd need to implement typescript module resolution. People would be surprised if importing Also, importing from multiple modules/files, you'd need to mimic TypeScript's type merging when a type is defined multiple times (this is technically needed for a single file too, but happens a lot less). I sometimes wish things weren't so complicated, but they are 😄 I'm closing this for now, but I'm not against implementing support for it. For that to be sustainable/maintainable though, I think it would need to be a separate implementation (a part from the current barebone one), using the TypeScript language server, or babel, or any other existing project that can load modules and understand how to mix/merge types. I'd also prefer help on this in terms of pointers to existing such implementations (using the language server for similar purposes), etc. It's a big effort to undertake. |
Should the time come where you revisit this one day, I would like to also mention a scenario where I currently miss this feature. It is a bit more complex than only an imported type which is why I think that using the full-blow typescript compiler, language server or whatever provides a suitable API is probably the best and most robust choice. The use case is generation of OpenAPI schemas for Nuxt.js server routes. Our consumers of the API is mostly the JS Frontend which in the case of Nuxt.js already have properly typed return values, however, there are also some consumers outside of the Nuxt project. I assume the same would also apply to Next.js though I am currently not using that. These server types can be obtained using the following: export type Foobar = Awaited<ReturnType<typeof import("server/api/something/[id].get").default>> The language server at least is properly able to resolve these types. |
Hi, we are consider using
typeconv
on our project. Although we heavily use imported types which don't seem to be working:A minimal reproducible example:
Then running
npx typeconv -f ts -t st -o out 'b.ts'
produces:Is there anything I'm doing wrong ? Or is this something thats not currently supported?
Thanks in advance.
The text was updated successfully, but these errors were encountered: