-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
tsc --init
produces tsconfig.json
which is not a 100% valid JSON document
#20384
Comments
This works as intended, Typescript can read these files. |
As @j-oliveras noted, the compiler/editors use the TS parser to parse the JSON file and is more permissive than the standard JSON format, e.g. trailing commas, missing quotes on property names, comments, etc.. |
@j-oliveras @mhegazy I strongly disagree with the decision to use a JSON-alike format instead of valid JSON, but that's obviously not in my control. As long as this is the expected behavior, this Github issue is definitely a bad bug report which I will close (my apologies for the false negative). Could any of you please provide me with directions on how I can achieve the following. I am writing a script that runs Thanks |
we were of the same mind for a long time. then we saw the value comments, being tolerant with trailing commas, etc, provides to users, so we become more pragmatic on this topic.
You can ether use the TS API to parse the file, it parses the file as a JS object literal. see |
@mhegazy That doesn't solve re-outputting the file with the original comments intact. @another-guy Possible easy solution: copy the generated tsconfig.json to another location and add your edits in a new tsconfig.json that extends the original:
More difficult: Ignore the JSON. Just treat the the file as a regular character stream. Edit however you want. |
@AnmAtAnm your understanding of my problem definition is more precised than @mhegazy's one. I'd like to preserve the comments as long as they are generated as a part of So, your proposal of extending the |
TypeScript Version:
Code
Expected behavior:
tsconfig.json
with 100% valid JSON content is generated.Actual behavior:
tsconfig.json
is generated, however it contains elements which make JSON invalid, such as//
and/**/
comments.It may be perceived as a minor issue, but not for the tools that either depend on
tsc
itself fortsconfig.json
generation, or depend on the generatedtsconfig.json
.The text was updated successfully, but these errors were encountered: