Skip to content

Fix tsconfig null override for extended configurations #1313

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

Merged
merged 14 commits into from
Jun 30, 2025
Merged

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 29, 2025

This PR fixes support for "nulling out" extended tsconfig.json properties by setting them to null.

Problem

When a tsconfig.json extends another tsconfig.json and tries to set a property to null to clear it, the current implementation doesn't handle this correctly. Consider:

// tsconfig-base.json
{
  "compilerOptions": {
    "types": ["node"]
  }
}

// tsconfig.json
{
  "compilerOptions": {
    "types": null
  },
  "extends": "./tsconfig-base.json"
}

Before this fix:

$ tsgo -p . --showConfig
{
  "types": ["node"],  // ❌ Still shows inherited value
  "configFilePath": "./tsconfig.json"
}

After this fix:

$ tsgo -p . --showConfig
{
  "configFilePath": "./tsconfig.json"
  // ✅ types field is omitted (successfully nulled out)
}

Root Cause

The issue was in the mergeCompilerOptions function which uses IsZero() to check if a field should be merged. In Go:

  • null in JSON → Go nil slice → IsZero() returns true → merge skips it
  • [] in JSON → Go empty slice → IsZero() returns false → merge applies it
  • Not set → Go nil slice → IsZero() returns true → merge skips it

This meant the merge function couldn't distinguish between "not set" and "explicitly set to null".

Solution

  • Added mergeCompilerOptionsWithRaw: A new merge function that's aware of explicitly set null values in the raw JSON
  • Added handleExplicitNullValues: Processes raw JSON to detect fields explicitly set to null and applies them as overrides
  • Updated tsconfig extending logic: Uses the new merge function during configuration extension

Test Coverage

Added comprehensive test cases:

  • Single field null override (tsconfigNullOverride.ts)
  • Multiple field null override (tsconfigNullOverrideMultipleFields.ts)
  • Verified existing behavior still works (empty arrays, inheritance, etc.)

All existing tests pass, confirming backward compatibility.

Fixes #768.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 29, 2025 08:18
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [bug] support nulling out extended tsconfig.json properties Fix tsconfig null override for extended configurations Jun 29, 2025
@Copilot Copilot AI requested a review from jakebailey June 29, 2025 08:35
Copilot finished work on behalf of jakebailey June 29, 2025 08:35
@jakebailey
Copy link
Member

The tests added here are bad; delete them and instead add tests to the existing tsconfig parsing tests in the tsoptions package, which generate better baselines. Also, make sure this works for other compiler options, not just "types".

…ypes

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 29, 2025

The tests added here are bad; delete them and instead add tests to the existing tsconfig parsing tests in the tsoptions package, which generate better baselines. Also, make sure this works for other c...

Addressed in commit 6d21ec0. Deleted the bad compiler tests and added comprehensive tsoptions package tests that properly test null overrides for array fields (types, lib, typeRoots), string fields (outDir, baseUrl, rootDir), and mixed field types including Tristate fields. The tests use the baseline system and work with both JSON API and JSONSourceFile API.

Copilot finished work on behalf of jakebailey June 29, 2025 08:52
…back

- Use strings.Cut instead of strings.Split for better performance
- Use targetField.SetZero() instead of reflect.Zero() for cleaner code
- Restructure function with early continues to reduce nesting and improve readability

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 29, 2025 16:45
Copilot finished work on behalf of jakebailey June 29, 2025 16:45
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 17:13
Copilot finished work on behalf of jakebailey June 30, 2025 17:13
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 17:15
- Fixed line 1043 to pass extendedConfig.raw instead of nil to mergeCompilerOptions
- Added test case demonstrating null overrides in middle level of extends chain
- This ensures null values are properly handled at each level of tsconfig extension

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 18:25
Copilot finished work on behalf of jakebailey June 30, 2025 18:25
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 18:38
Copilot finished work on behalf of jakebailey June 30, 2025 18:38
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 18:59
Copilot finished work on behalf of jakebailey June 30, 2025 18:59
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@Copilot Copilot AI requested a review from jakebailey June 30, 2025 19:12
Copilot finished work on behalf of jakebailey June 30, 2025 19:12
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot finished work on behalf of jakebailey June 30, 2025 19:56
@jakebailey jakebailey marked this pull request as ready for review June 30, 2025 20:04
@jakebailey jakebailey enabled auto-merge June 30, 2025 20:21
@jakebailey jakebailey added this pull request to the merge queue Jun 30, 2025
Merged via the queue into main with commit 8fbfa3e Jun 30, 2025
22 checks passed
@jakebailey jakebailey deleted the copilot/fix-768 branch June 30, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] support nulling out extended tsconfig.json properties
4 participants