我想使用 vim
的 syntastic
插件,在我使用 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
。
详情
作为romainl在 his 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/