在vim中使用tsconfig.json进行tsc with syntastic

osd*_*iab 12 vim typescript syntastic

我想使用syntastic插件为vim我提供实时错误检查,同时我正在编写打字稿文件,使用tsc.我已经tsc激活了vim.有关如何tsc使用最接近的父tsconfig.json文件作为配置的任何建议?我发现tsc默认情况下没有这样做,这使syntastic配置变得困难.谢谢!

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

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

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()]
Run Code Online (Sandbox Code Playgroud)

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

app.ts|| TS5042: Option 'project' cannot be mixed with source files on a command line.
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*kin 19

摘要

添加let g:syntastic_typescript_tsc_fname = ''.vimrc.

细节

正如romainl他的回答中提到的,Typescript wiki 的"Using tsconfig.json"部分说明:

通过在没有输入文件的情况下调用tsc,在这种情况下,编译器将搜索tsconfig.json从当前目录开始并继续父目录链的文件.

您可以使用SyntasticVim中添加以下内容,或者如果您使用Janus,可以在LCD 047Syntastic问题#1628的答案中找到:.vimrc.vimrc.after

let g:syntastic_typescript_tsc_fname = ''
Run Code Online (Sandbox Code Playgroud)