tsc.nvim icon indicating copy to clipboard operation
tsc.nvim copied to clipboard

:TSC Command Doesn't Detect Errors with Split tsconfig

Open m4a1j9 opened this issue 10 months ago • 1 comments

Current Behavior

In a project that uses a split tsconfig setup (e.g., tsconfig.app.json), running the :TSC command outputs "No errors found", even when there are errors.

However, if all configurations from tsconfig.app.json are merged into tsconfig.json, the command works as expected and detects errors immediately.

Expected Behavior

The :TSC command should detect and report all TypeScript errors across the entire project, even when using a split tsconfig setup.

Steps to Reproduce

  1. Create a new React + Vite project with TypeScript:
    yarn create vite my-app --template react-ts
    cd my-app
    yarn
    
  2. Open any file and introduce a syntax error.
  3. Run :TSC in Neovim.
  4. Observe that no errors are reported, even though they exist.

What I've Tried

1. Manually Setting the Project Path

Configured tsc.nvim to explicitly use tsconfig.app.json:

{
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      flags = {
        watch = true,
        project = "tsconfig.app.json"
      },
    })
  end,
}

➡️ Result: Still doesn't detect errors.

2. Using a Dynamic Configuration (Based on #39)

local M = {}

local find_closest_file = require("plugins.utils.find-file").find_closest_file

local tsconfig_path = find_closest_file({ "tsconfig.app.json", "tsconfig.json" })

if tsconfig_path then
  print(tsconfig_path)
  M.plugin = {
    "dmmulroy/tsc.nvim",
    config = function()
      require("tsc").setup({
        flags = {
          watch = true,
          project = tsconfig_path
        },
      })
    end,
  }
else
  M.plugin = {}
end

return M

➡️ Result: Correctly detects tsconfig.app.json or tsconfig.json dynamically, but :TSC still doesn't work.

Additional Notes

  • The issue seems related to how tsc.nvim resolves the project configuration.
  • Running npx tsc --project tsconfig.app.json in the terminal correctly reports errors.
  • It’s unclear if tsc.nvim is properly handling non-default tsconfig paths.

Any insights or fixes would be appreciated! 🚀

m4a1j9 avatar Feb 14 '25 13:02 m4a1j9

I believe the issue is in this line: https://github.com/dmmulroy/tsc.nvim/blob/d38264b5712ce9dc2f39dff43121bbd164814528/lua/tsc/init.lua#L299

The project flag provided in the options is overriden by any tsconfig.json found by auto-detection logic.

@m4a1j9 As a workaround, it seems like passing flags as a string skips this logic and allows you to pass the project you need.

{
  "dmmulroy/tsc.nvim",
  config = function()
    require("tsc").setup({
      flags = "--watch --project=tsconfig.app.json",
    })
  end,
}

TimShilov avatar Feb 26 '25 21:02 TimShilov

I think a solution to this is a) specifying your flags as a string, and b) including --build in your flags.

Example:

flags = "--build --noEmit"

The reason you need to specify your flags as a string is that --build must be the first argument to the TypeScript compiler, and tsc.nvim does not necessarily keep it in that position if you specify your flags as a table.

Passing --build makes the TypeScript compiler run for all references in your tsconfig.json, which might look like this in a vite project:

{
  "files": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ]
}

mmirus avatar Sep 09 '25 15:09 mmirus

#71 should have hopefully resolved this 🤞

dmmulroy avatar Nov 12 '25 13:11 dmmulroy