🔎 Search Terms
tailing comma
🕗 Version & Regression Information
⏯ Playground Link
No response
💻 Code
npx tsc --init
trim-tsconfig
Where the content of the trim-tsconfig script is as below:
#!/usr/bin/env node
let fs = require('fs')
let file = process.argv[2] || 'tsconfig.json'
let content = fs
.readFileSync(file, 'utf8')
.split('\n')
.filter(line => !line.trim().startsWith('//'))
.join('\n')
.replace(/\/\*.*\*\//g, '')
.split('\n')
.filter(line => line.trim())
.map(line => line.trimEnd())
.join('\n')
fs.writeFileSync(file, content)
🙁 Actual behavior
The produced tsconfig.json contains tailing comma, which is not compatible with JSON.parse()
🙂 Expected behavior
The produced tsconfig.json should be compatible with JSON.parse()
Additional information about the issue
In versions before 5.8, the tsconfig.json created by tsc --init contains comments, which is not a compatible format of JSON that could not be parsed by JSON.parse(). It was trivial to remove the comments with // ... and /* ... */.
However since version 5.9, the tsconfig.json created by tsc --init contains tailing comma, which is hard to be preprocessed, for passing to JSON.parse().
The current version of tsc --init support wide range of arguments, e.g. --module commonjs and --outDir dist.
Could we enhance tsc --init to also support disabling tailing comma (e.g. --omitTailingComma), or even omitting the comments (e.g. --omitComments)?
Workaround is to use the old version before the fix is released, as raised in #58420 (comment)
🔎 Search Terms
tailing comma
🕗 Version & Regression Information
⏯ Playground Link
No response
💻 Code
Where the content of the
trim-tsconfigscript is as below:🙁 Actual behavior
The produced
tsconfig.jsoncontains tailing comma, which is not compatible withJSON.parse()🙂 Expected behavior
The produced
tsconfig.jsonshould be compatible withJSON.parse()Additional information about the issue
In versions before 5.8, the
tsconfig.jsoncreated bytsc --initcontains comments, which is not a compatible format of JSON that could not be parsed byJSON.parse(). It was trivial to remove the comments with// ...and/* ... */.However since version 5.9, the
tsconfig.jsoncreated bytsc --initcontains tailing comma, which is hard to be preprocessed, for passing toJSON.parse().The current version of
tsc --initsupport wide range of arguments, e.g.--module commonjsand--outDir dist.Could we enhance
tsc --initto also support disabling tailing comma (e.g.--omitTailingComma), or even omitting the comments (e.g.--omitComments)?Workaround is to use the old version before the fix is released, as raised in #58420 (comment)