Skip to content
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

Clarify documentation on tsconfig usage #2062

Closed
slhck opened this issue Sep 6, 2024 · 7 comments · Fixed by #2068
Closed

Clarify documentation on tsconfig usage #2062

slhck opened this issue Sep 6, 2024 · 7 comments · Fixed by #2068
Assignees

Comments

@slhck
Copy link
Contributor

slhck commented Sep 6, 2024

Per #168 I understand that tsconfig.json is not read by default. This was confusing to me, as I have a project where building schemas failed due to this error:

➜ npx ts-json-schema-generator --path src/types/config.ts --type Config
error TSJ - 108: Type check error

  /Users/werner/Documents/Projects/test/node_modules/@types/selenium-webdriver/bidi/captureScreenshotParameters.d.ts:9:5
    9     #map: Map<string, any>;
          ~~~~
    Private identifiers are only available when targeting ECMAScript 2015 and higher.

Yet in my tsconfig.json I have specified ES2023 as a target.

I only then realized that I needed to explicitly pass the tsconfig.json file to the command to make it work. Just from the CLI args I would have assumed that "Custom tsconfig.json path" means: "Any config other than tsconfig.json".

Is that behavior intentional? (One would assume that proper type compilation also requires knowing about the project's build target, but maybe this is not as big of a problem as I think it is for most users.)

It would be great if the documentation could be updated to reflect that aspect. Maybe I'm the first one to get bitten by this, but from a quick review I haven't found similar issues. Let me know how you think this could be best addressed and I can provide a PR!

@arthurfiorette
Copy link
Collaborator

arthurfiorette commented Sep 6, 2024

I guess its this way to don't break current users @domoritz? We should load tsconfig.json by default.

#1966 fixed this but moving to another CLI was impossible without breaking changes.

@arthurfiorette arthurfiorette self-assigned this Sep 6, 2024
@slhck
Copy link
Contributor Author

slhck commented Sep 6, 2024

Thanks for the clarification! I would expect most of these type of tools to automatically load the existing tsconfig.json. Then again, this might not work if the user is doing something esoteric with the options that would be prevent ts-json-schema-generator from doing its job, in which case you could either:

  • Force-overwrite some options to make it work
  • Error out and tell the user that they have a conflicting option set

I, personally, don't mind breaking CLI changes if they allow for more flexibility down the line.

@domoritz
Copy link
Member

domoritz commented Sep 6, 2024

The tool should definitely work without a tsconfig file but I think it makes sense to load the default file at the default paths (same way as tsc). We can make in a new major version. I'm cool with that.

@arthurfiorette
Copy link
Collaborator

Awesome, @slhck, would you want to work on a PR for this? Remember to add unit tests :)

@domoritz
Copy link
Member

domoritz commented Sep 7, 2024

And use the logic from tsc for finding the file if possible.

@arthurfiorette
Copy link
Collaborator

@slhck
Copy link
Contributor Author

slhck commented Sep 7, 2024

Oh, actually I was referring to providing a PR for the docs only to address the current behavior. I'm not sure if I can change the package internals. So you mean just adding a new default value for the tsconfig option?

slhck added a commit to slhck/ts-json-schema-generator that referenced this issue Sep 9, 2024
This looks up the default tsconfig.json file for the current project when used from the CLI, to avoid possible compliation errors. Fixes vega#2062
slhck added a commit to slhck/ts-json-schema-generator that referenced this issue Sep 9, 2024
This looks up the default tsconfig.json file for the current project when used from the CLI, to avoid possible compliation errors. Fixes vega#2062
slhck added a commit to slhck/ts-json-schema-generator that referenced this issue Sep 30, 2024
This looks up the default tsconfig.json file for the current project when used from the CLI, to avoid possible compliation errors. Fixes vega#2062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants