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
Disambiguate type with same name in different files #113
Comments
If I remember correctly, this tool should throw a warning when there are multiple types with the same name. Disambiguation should actually not be required if only one type is actually needed to produce the output. |
Can be reproduced by generating the schema for // test2.ts
export type Field = string | number; // test.ts
import { Field as Field2 } from "./test2";
export type Field = string;
export type MyObject = {
a: Field;
b: Field2;
}; Will produce the error message |
Oh, I'm sorry, I think I misunderstood this issue. This is more about having multiple types with the same name and telling the generator for WHICH type the schema should be generated. MY problem is different so the reproduction above does not belong here. I'm opening a new issue (Created #143) |
Yes, my problem is that there are some cases in which some types have the same name (sometimes the names are duplicated by some imported types, from external libraries), and I need to tell the generator for which type the schema should be generated. The example by @kayahr is correct, but I need to tell the generator that i need the schema for |
YousefED/typescript-json-schema#151 introduced a |
I believe that is a different issue. What I'm looking for is a way to specify for which type I want a schema to be generated. The issue you are referencing seems to be about how to export multiple types with the same name, if I understand correctly.. |
I see. We don't really need an option then because TypeScript already knows what your you're referring to, right? To me, there is no ambiguity to resolve, but there is a bug. |
I may be missing something, but I don't know how I can tell the generator that I want the schema for MyType in File.ts and not MyType in File2.ts. When both File.ts and File2.ts are part of my typescript project. |
Ohh, so this is about the root type only. I see. Ideally, this would just work if you provide the file with |
Right, except (if I understand correctly) using |
You can use both |
Hi, I checked. tsconfig.json
main.ts
custom.d.ts
scriptData.ts
npx ts-json-schema-generator -t ScriptData -f .\tsconfig.json
npx ts-json-schema-generator -t ScriptData -f .\tsconfig.json -p .\scriptData.ts
|
I don't plan to implement this feature and therefore will close this issue. If anyone needs it, I would be more than happy to review a pull request. |
In my use case I need to disambiguate what specific type I want to convert, and in a given project there might be more than one type with the same name, in different files.
As in my extension the user activates ts-json-schema-generator with reference to a specific file, the ability to specify a file when searching for types would greatly help. At the moment I'm implementing the ability in a fork, but I would love to depend on the original library.
The text was updated successfully, but these errors were encountered: