-
Notifications
You must be signed in to change notification settings - Fork 804
Fix --showConfig to print enumerated value names, not integers #2571
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
|
Is this not exactly the same as #2570? There are no tests (CLI tests for --showConfig should be very easy), and these methods will affect tsbuildinfo, so it must not have run the tests? |
|
Honestly, I think this approach is hopeless. This won't handle implied options like the old code. I think that we need to port the old code, but adapt it to work more similarly to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates JSON serialization for several compiler and watch option enums so that --showConfig outputs human-readable enum names (e.g. "moduleDetection": "force") instead of raw integer values (e.g. "moduleDetection": 3).
Changes:
- Added
MarshalJSONimplementations forJsxEmit,ScriptTarget,ModuleKind,ModuleResolutionKind,ModuleDetectionKind, andNewLineKindincompileroptions.goto emit string names (ornullfor unset/sentinel values). - Added
MarshalJSONimplementations forWatchFileKind,WatchDirectoryKind, andPollingKindinwatchoptions.goto emit string names (ornull) for watch-related options.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/core/compileroptions.go | Adds custom JSON marshaling for core compiler option enums so they serialize to descriptive strings instead of integers. |
| internal/core/watchoptions.go | Adds custom JSON marshaling for watch-related enums so watch options can also serialize to descriptive strings. |
| func (j JsxEmit) MarshalJSON() ([]byte, error) { | ||
| switch j { | ||
| case JsxEmitNone: | ||
| return []byte("null"), nil | ||
| case JsxEmitPreserve: | ||
| return []byte(`"preserve"`), nil | ||
| case JsxEmitReactNative: | ||
| return []byte(`"react-native"`), nil | ||
| case JsxEmitReact: | ||
| return []byte(`"react"`), nil | ||
| case JsxEmitReactJSX: | ||
| return []byte(`"react-jsx"`), nil | ||
| case JsxEmitReactJSXDev: | ||
| return []byte(`"react-jsxdev"`), nil | ||
| default: | ||
| return []byte("null"), nil | ||
| } | ||
| } | ||
|
|
||
| func (s ScriptTarget) MarshalJSON() ([]byte, error) { | ||
| switch s { | ||
| case ScriptTargetNone: | ||
| return []byte("null"), nil | ||
| case ScriptTargetES5: | ||
| return []byte(`"es5"`), nil | ||
| case ScriptTargetES2015: | ||
| return []byte(`"es2015"`), nil | ||
| case ScriptTargetES2016: | ||
| return []byte(`"es2016"`), nil | ||
| case ScriptTargetES2017: | ||
| return []byte(`"es2017"`), nil | ||
| case ScriptTargetES2018: | ||
| return []byte(`"es2018"`), nil | ||
| case ScriptTargetES2019: | ||
| return []byte(`"es2019"`), nil | ||
| case ScriptTargetES2020: | ||
| return []byte(`"es2020"`), nil | ||
| case ScriptTargetES2021: | ||
| return []byte(`"es2021"`), nil | ||
| case ScriptTargetES2022: | ||
| return []byte(`"es2022"`), nil | ||
| case ScriptTargetES2023: | ||
| return []byte(`"es2023"`), nil | ||
| case ScriptTargetES2024: | ||
| return []byte(`"es2024"`), nil | ||
| case ScriptTargetESNext: | ||
| return []byte(`"esnext"`), nil | ||
| case ScriptTargetJSON: | ||
| return []byte(`"json"`), nil | ||
| default: | ||
| return []byte("null"), nil | ||
| } | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new MarshalJSON implementations for the enum fields (JsxEmit/ScriptTarget/ModuleKind/ModuleResolutionKind/ModuleDetectionKind/NewLineKind) change the JSON shape of core.CompilerOptions from numeric enum values to strings, but there are existing tests that round-trip CompilerOptions through json.Marshal/json.Unmarshal (e.g. internal/tsoptions/commandlineparser_test.go:225–229 and 331–334). Since these enum types do not implement UnmarshalJSON, json.Unmarshal will still expect numeric JSON tokens for these int32-backed fields, so it will fail (or at least diverge from the TypeScript baselines) when given the new string values like "react" or "es2020". To keep the tests and any other JSON consumers working, consider either (a) adding matching UnmarshalJSON implementations for these enum types that accept the same string representations, or (b) leaving the default JSON for core.CompilerOptions as numeric and instead introducing a dedicated DTO or adapter used only by --showConfig that serializes enum values as strings.
--showConfigwas printing raw integer values for enum options (e.g.,"moduleDetection": 3) instead of their string names ("moduleDetection": "force").Changes
Added
MarshalJSON()methods to compiler option enum types:JsxEmit,ScriptTarget,ModuleKind,ModuleResolutionKind,ModuleDetectionKind,NewLineKindWatchFileKind,WatchDirectoryKind,PollingKindBefore/After
{ - "jsx": 3, - "module": 99, - "moduleDetection": 3, - "target": 7 + "jsx": "react", + "module": "esnext", + "moduleDetection": "force", + "target": "es2020" }Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.