-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
🔎 Search Terms
tailing comma
🕗 Version & Regression Information
- This changed between versions 5.8 and 5.9
- This changed in commit or PR tsc --init update #61813
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about tsc --init update 2024 #58420 (comment)
⏯ Playground Link
No response
💻 Code
npx tsc --init
trim-tsconfigWhere 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)