Repository navigation
Description
Suggestion
As a professional TypeScript developer, I start new TS projects all the time. I use tsc --init sometimes, but more often than not I copy tsconfig.json files from other projects because I find the tsconfig.json file that is generated to be horribly spammy.
Having a tsc --init command is valuable to me, because quite often I want to bootstrap a project quickly, but the comments get in my way, as they make it harder to read what the actual config of a project is, and generally look really messy. If I ever run tsc --init the first thing I do is strip out these comments.
I'd really appreciate a tsc --init-basic (or something like it) that provides the same basic configuration set but without any comments.
- Note; I suspect this would be super simple to implement, and I'm looking for opportunities to start contributing, so if anyone can point me towards the appropriate area in the codebase, I'd be happy to submit this change myself.
🔍 Search Terms
tsconfig comments init
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Activity
benwainwright commentedon Oct 1, 2021
I've now forked the repo and worked out how to make this change. I appreciate the issue is still to be accepted; if not, no worries, I'll consider a useful exercise in introducing myself to a codebase I'd like to contribute in.
If you believe this feature has enough value for my contribution to be included, the remaining guidance I need in order to finish my patch are on these areas:
src/compiler/commandLineParser.ts. The corresponding test file doesn't appear to have anything related to this functionality, and nothing that wasn't a baseline failed when I added my flag, so it doesn't look like the--initflag is specifically tested beyond the baseline (that I can see)to generate the correct message in the help screen, I had to add to the diagnostics json file. I can see that the number of the original 'init' description isI've found the documentation on this, will look for a free 6xxx series code6070. None of the numbers around that point are free so I had to go to the bottom of the file to find a code that was free. Is there any significance behind these numbers; is there any issue with it--initSimple. I'm not precious about this, though shorter is better (which is why I didn't go with--initWithoutComments). Any alternatives will be happily accepted.fatcerberus commentedon Oct 1, 2021
I think this is just a fancy way of saying “If you make a code change, you should write (or modify) one or more tests for it, and at least one of the new tests must fail without your change.”
It doesn’t mean your change has to cause existing tests to fail, although of course it may, in which case that has to be dealt with too.
andrewbranch commentedon Oct 1, 2021
FWIW I’ve always wanted this feature, but I’m not confident that a PR would get accepted and I would hate to see you burned by infinite bikeshedding as a first time contributor. If this feature is your passion, don’t let me stop you from implementing it, but be prepared that a PR for an “awaiting more feedback” issue may or may not ever get a proper review. If you are just looking to start contributing to TS anywhere, I would encourage you to search for “help wanted” and “good first issue” labels, where you’re much more likely to get support with a PR from start to finish.
benwainwright commentedon Oct 1, 2021
I mean passion is a strong way of putting it. I believe this change is a no brainer given the ratio of effort to value... but if the PR isn't accepted I'll live as I can just continue copying from my other projects 🤷🏻♂️ . From a personal point of view it was a useful excuse to check out the code and understand how to make changes in
tscwithout having to do too much thinking.benwainwright commentedon Oct 1, 2021
I'm aware of this and have started digging through these tickets. But I've not yet found anything which I thought was suitable for my very limited understanding of the codebase yet (and wasn't already 'claimed'). This is a use case I fully understand (because it's for me) and the implementation is very accessible.
andrewbranch commentedon Oct 1, 2021
Well, maybe to get some momentum one way or another: Martin Johns (@MartinJohns), why are you not a fan?
MartinJohns commentedon Oct 1, 2021
Andrew Branch (@andrewbranch) I'm generally opposing any new flags or options that bring no real benefit, and I'd say this flag brings no real benefit. It adds bloat (code and feature wise) and is just another option to do the same thing, causing slight fragmentation. Also there's a possible risk of those two init configs diverging, although I believe the code already is smarter than that and the file(s) would be / is generated dynamically.
If a lot of people consider this a value worth adding, I'd say go ahead. But for a few individual cases there are plenty of alternative options (e.g. extending config from npm package, copy existing file, have a local command that generates the file), although these would have to be maintained to make use of new flags in newer versions.
I can see the appeal, but my gut feeling towards such features is a no.
andrewbranch commentedon Oct 1, 2021
I think I create (and edit) more tsconfigs than the average person since a big part of my job is creating repros of bugs. I agree this isn’t a big value add, but if it existed, I would definitely use it and it would make me happy. On the other hand, I would personally not care about this at all if VS Code had a “strip all comments” command built in, as that would be just as fast for my workflow.
benwainwright commentedon Oct 2, 2021
Martin Johns (@MartinJohns)
For the record, since I've already implemented the change on a fork, I can tell you that the file is indeed generated dynamically and because of the way it is done, there is no risk of divergence.
I mean that's a matter of opinion I guess, but I do appreciate that there are other options.
Andrew Branch (@andrewbranch)
To be honest, I'm a vim user (yeah, sorry - one of those people 😉) and when you put it like that - it will probably take me about 20 minutes to write a vim mapping to do this. It just hadn't occurred to me that anyone would argue against this to be honest, since I've not yet worked with anyone who finds these kind of comments in config files useful at all, and plenty who find them annoying. I'd actually be very much in favour of just removing them outright, but I suspect that would be an even harder sell...
orta commentedon Oct 2, 2021
I think I'd probably argue against this personally - especially given that @tsconfig/bases exists and at this point has a base for a lot of common JS projects.
I'd think I'd be open to
tsc --init --extendswhich for example:yarn tsc --init --extends @tsconfig/node14 Created a new tsconfig.json with: extends: @tsconfig/node14 You can learn more at https://aka.ms/tsconfig.json cat tsconfig.json { "extends": "@tsconfig/node14" "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ } }This doesn't introduce a new concept to teach (e.g. there's new one flag which only works with
--init) but instead extends the idea of 'you can set your own custom tsconfig options from the CLI' to also includeextends.MartinJohns commentedon Oct 2, 2021
Andrew Branch (@andrewbranch) Well, technically VS Code has such a feature... Kind of, using "Replace" and a Regular Expression.
I quickly hacked together the Regular Expression I used and it's not the prettiest, but it works:
(\n\s+/\*.*(?!\*/))|(\n\s+//[^\n]*)|(\s+/\*.*(?!\*/))fatcerberus commentedon Oct 2, 2021
ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ
🚎
benwainwright commentedon Oct 4, 2021
Orta Therox (@orta) that's actually a great idea. What do you think the likelihood of me getting that in if I were to have a go at implementing it?
cdaringe commentedon Mar 15, 2022
i skim read the above post, got super stoked, and was so disappointed that it wasn't real! 😉
i create a new TS project MAX 1x/day, MIN 3x/week. ya, the flag in question is frivolous at large, but clearly of value enough s.t. ...hey.. here we all are talkin' about it 😄
On the
--extendsflag idea, I often wouldn't want to install@tsconfig/nodeXY, just use that as my base.yukulele commentedon Dec 15, 2022
I think
tsc --initshould always create atsconfig.jsonfile without comments :tsconfig.jsonis not the documentation.tsc --initgive a link to the documentation (https://aka.ms/tsconfig) in the terminal.Eventually an option (like
--init-all) could allow to generate atsconfig.jsonfile with all possible options, not commented, with their default values.xgqfrms commentedon Oct 12, 2023
Enhance
tscclihttps://github.com/microsoft/TypeScript/blob/main/src/executeCommandLine/executeCommandLine.ts
https://github.com/microsoft/TypeScript/blob/main/src/compiler/commandLineParser.ts#L586
System233 commentedon Oct 13, 2023
Okay, PR #56051 is suspended, now let's continue from here.
There are a few questions for all
tsc --initbefore?tsconfig.jsonfiles with a significant number of comments?tsconfig.jsonfiles with a significant number of comments?tsconfig.json?tsconfig.json?tsconfig.jsonis heavily commented, do you remove the comments?tsc --init, how likely is it for the comments' indentation to become disordered when you edit thetsconfig.jsonconfiguration?tsconfig.jsonand ensure that comment alignment remains undisturbed?tsconfig.json, can you tolerate a misaligned configuration file if the comments' alignment becomes disrupted?Comments
Originally posted by Orta Therox (@orta) in #56051 (comment)
Yes, it's very valuable, but only for the first time, and why don't you use it in your repository tsconfig/bases like this?
Source: tsconfig/bases/node20.json
The
tsconfig.jsonis not an API reference. Maybe you can try creating a project withtsc --initevery day. I believe you will spend a lot of time deleting comments because a large number of comments seriously affect the readability of the actual configuration of the project.The best documentation is code, not comments.
If you do need documentation, as mentioned in the comments, please visit https://aka.ms/tsconfig.
Originally posted by System233 in #56051 (comment)
Let’s see if there are a lot of comments in various configuration files in popular repositories
microsoft/vscode
tsconfig.json
tsconfig.base.json
tsconfig.monaco.json
tsconfig.tsec.json
tsconfig.vscode-dts.json
microsoft/fluentui
tsconfig.json
tsconfig.base.all.json
tsconfig.base.json
tsconfig.base.v0.json
tsconfig.base.v8.json
microsoft/playwright
tsconfig.json
DefinitelyTyped
tsconfig.json
types/*/tsconfig.json
Nest
tsconfig.json
tsconfig.spec.json
Vue
tsconfig.json
types/tsconfig.json
angular/angular
tsconfig.json
*/tsconfig.json
There are too many cases to support this PR, even Microsoft itself doesn't like writing a lot of comments in
tsconfig.json👍 .Originally posted by System233 in #56051 (comment)
Next, let's check if there are a significant number of comments in the template configuration file located in tsconfig/bases.
tsconfig/bases
It can be seen that an excellent
tsconfig.jsonshould be clean and tidy, without an abundance of unnecessary comments. However, if comments are considered valuable, they should be added to the tsconfig/bases template configuration.Please consider adding comments there rather than removing them Orta Therox (@orta) .
Originally posted by System233 in #56051 (comment)
Some comments from Typescript members
Originally posted by Ryan Cavanaugh (@RyanCavanaugh) in #34686 (comment)
Originally posted by Daniel Rosenwasser (@DanielRosenwasser) in #34686 (comment)
Perhaps someone can conduct a data analysis on the proportion of comment lines in all tsconfig.json files in the DefinitelyTyped repository to determine if an abundance of comments in tsconfig.json is a common occurrence.
The reality is that no one ever writes extensive comments in
tsconfig.json.Orta Therox (@orta), why don't you keep comments in your project tsconfig/bases?
Martin Johns (@MartinJohns), why do you always want to remove some of the comments generated by
tsc --initin your project? Please keep them intact vscode-inline-types/tsconfig.json.I will never use
@tsconfig/*. Why extend an unrelated project just for a few lines of configuration? It's like saying I know the configuration generated bytsc --initis very ugly, so I choose tocp other-project/tsconfig.json .to start a new project.Isn't it better to have
tsc --initgenerate a basic configuration file, and let developers have direct control over all the settings?Readability test
Did you see a lot of errors in the
tsconfig.jsondiff snippet above?crazyjat commentedon Oct 13, 2024
Literally no one wants the comments. It is incredibly stupid that this is the default AND there is no way to disable them. What a waste of everyone's time.
Edit: Got thumbed down by someone that loves unnecessary comments. I hate people like you.
System233 commentedon Oct 13, 2024
This is pure arrogance—completely ignoring the community's voice.
Those with a vested interest in the tsconfig/bases repository have no right to oppose here. They don’t even like having comments in their own tsconfig and have chosen to remove all of them, yet they oppose others who want to remove comments from their tsconfig. If you don't even use it yourself, why force it on others? Is this the infamous double standard at work? Please, just put the comment back in your tsconfig/bases!
At the top of the tsconfig file, there’s already a comment linking to the documentation. Even adding a $schema would be a thousand times better than dumping a load of shit into the tsconfig.
crazyjat commentedon Oct 13, 2024
tsc --init is a waste of time. Why have a feature that is completely useless? Especially if I have to spend twice as much time removing the comments. I'll never use it again. Arrogance doesn't even begin to describe it. It's more like hatred for your users.
dcavalcante commentedon Nov 4, 2024
So.. hear me out: #60407
broofa commentedon Mar 20, 2025
For those of you annoyed by the comment-spam of
tsc --init, Ryan Cavanaugh (@RyanCavanaugh)'stsc-initwizard may be of interest. It asks the salient questions, then generates a comment-less config file as the end result.("Hmm.... if
tsc --init --wizardwere to open that web page in a browser we could probably close this issue... 🤔 ")[Edit: Actually, it looks like this and other
tsc --initrelated issues will be addressed in #58420 ]cdaringe commentedon Mar 20, 2025
Thanks for sharing Robert Kieffer (@broofa)! The site is helpful, and I love the suggestion too
jakebailey commentedon Jun 30, 2025
With #58420 now fixed, I believe this has issue has run its course.