vim - 使用 tsconfig.json for tsc with syntastic in vim

标签 vim typescript syntastic

我想使用 vimsyntastic 插件,在我使用 tsc 编写 typescript 文件时为我提供实时错误检查。我已经在 vim 中激活了 tsc。关于如何让 tsc 使用最近父级的 tsconfig.json 文件作为配置的任何建议?我发现 tsc 默认情况下不这样做,这使得 syntastic 配置变得困难。谢谢!

编辑:我认为它没有使用 tsconfig.json 的原因是因为像模块解析方法这样的选项似乎不起作用(“require”未定义),而且它也不是t 捕获我在 tsconfig.json 中的 files 属性中定义的定义文件。

我尝试解决这个问题失败了:

let g:syntastic_typescript_checks=['tsc', 'tslint']

" typescript: find tsconfig.json
function! FindTypescriptRoot()
    return fnamemodify(findfile('tsconfig.json', './;'), ':h')
endfunction

let g:syntastic_typescript_tsc_args=['-p', FindTypescriptRoot()]

这导致 Syntastic 向我吐出这个错误:

app.ts|| TS5042: Option 'project' cannot be mixed with source files on a command line.

这可能是因为它正在运行类似 tsc -p/path/to/project/app.ts 的命令,这是对该标志的非法使用...但我不明白为什么我在 tsconfig.json 中的设置被 syntastic 忽略了:(

最佳答案

总结

添加 let g:syntastic_typescript_tsc_fname = ''.vimrc

详情

作为romainlhis answer 中提到, "Using tsconfig.json" Typescript wiki 的部分说明:

By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

您可以在 Vim 中执行此操作使用 Syntastic通过将以下内容添加到您的 .vimrc.vimrc.after 如果您使用 Janus ,如 LCD 047 中所见对您的 Syntastic issue #1628 的回答:

let g:syntastic_typescript_tsc_fname = ''

关于vim - 使用 tsconfig.json for tsc with syntastic in vim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34102184/

相关文章:

ruby-on-rails - 在 Vim 中使用 Pry 的 vim-ruby-debugger 样式断点

vim - 如何重新映射键绑定(bind)以将 vscode vim 扩展中的模式从插入模式更改为正常模式?

c++ - 将 c++11 正确添加到 Syntastic

vim - 在 vim 中插入类似行时,如何最大限度地减少击键次数?

typescript - 使用自定义 promise 作为通用类型

typescript - Typescript 中是否需要访问器?

javascript - Nestjs 中的模块解析

haskell - 如何避免 "‘main’ 未在模块 ‘Main’ 中定义“使用合成时

javascript - vim 与 syntastic 和 eslint : show warnings

vim - textwidth=78(而不是80)的原因/来源是什么?