This Neovim plugin provides an asynchronous interface to run project-wide TypeScript type-checking using the TypeScript compiler (tsc
). It displays the type-checking results in a quickfix list and provides visual notifications about the progress and completion of type-checking.
- Project-wide type checking
- Asynchronous execution of the TypeScript compiler to prevent lock ups and input lag
- Progress notifications with spinner animation
- Quickfix list for navigating errors
- Automatic opening of the quickfix list if there are errors
- User-friendly command
:TSC
tsc-errors.mov
tsc-no-errors.mov
Usage without nvim-notify
Screen.Recording.2023-04-23.at.9.50.43.AM.mov
To install the plugin, use your preferred Neovim plugin manager.
To install the plugin using packer.nvim, add the following to your plugin configuration:
use('dmmulroy/tsc.nvim')
To install the plugin using vim-plug, add the following to your plugin configuration:
Plug 'dmmulroy/tsc.nvim'
Then run :PlugInstall
to install the plugin.
For an enhanced UI/UX experience, it is recommended to install the nvim_notify plugin as well. This plugin is optional, and the plugin will work without it.
To set up the plugin, add the following line to your init.vim
or init.lua
file:
require('tsc').setup()
To run TypeScript type-checking, execute the :TSC
command in Neovim. The plugin will display a progress notification while the type-checking is in progress. When the type-checking is complete, it will show a notification with the results and open a quickfix list if there are any errors.
By default, the plugin uses the default tsc
command with the --noEmit
flag to avoid generating output files during type-checking. It also emulates the default tsc behavior of performing a backward search from the current directory for a tsconfig
file. The flags option can accept both a string and a table. Here's the default configuration:
{
auto_open_qflist = true,
auto_close_qflist = false,
bin_path = utils.find_tsc_bin(),
enable_progress_notifications = true,
flags = {
noEmit = true,
project = function()
return utils.find_nearest_tsconfig()
end,
},
hide_progress_notifications_from_history = true,
spinner = { "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" },
}
With this configuration, you can use keys for flag names and their corresponding values to enable/disable the flag (in the case of noEmit = true
) or provide a function (as in the case of the project
). This makes the configuration more explicit and easier to read. Additionally, the flags option is backwards compatible and can accept a string value if you prefer a simpler configuration:
flags = "--noEmit",
It's likely that the overwritten default vim.notify
function isn't returning nvim-notify
's notification record, which is used to replace the existing notification. Make sure that you're nvim-notify configuration looks something like this:
require('notify')
vim.notify = function(message, level, opts)
return notify(message, level, opts) -- <-- Important to return the value from `nvim-notify`
end
In a monorepo setup, tsc.nvim only typechecks the project associated with the nearest tsconfig.json
by default. If you need to typecheck across all projects in the monorepo, you must change the flags configuration option in the setup function to include --build
. The --build
flag instructs TypeScript to typecheck all referenced projects, taking into account project references and incremental builds for better management of dependencies and build performance. Your adjusted setup function should look like this:
require('tsc').setup({
flags = {
build = true,
},
})
With this configuration, tsc.nvim will typecheck all projects in the monorepo, taking into account project references and incremental builds.
Feel free to open issues or submit pull requests if you encounter any bugs or have suggestions for improvements. Your contributions are welcome!
This plugin is released under the MIT License. See the LICENSE file for details.