Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use tsconfig.json for tsc with syntastic in vim

I want to use the syntastic plugin for vim to give me live error checking while I'm writing typescript files, using tsc. I already have tsc activated in vim. Any suggestions for how I could get tsc to use the closest parent's tsconfig.json file as configuration? I find that tsc doesn't do so by default, which makes syntastic configuration difficult. Thanks!

EDIT: The reason I think it's not using tsconfig.json is because options like the module resolution method doesn't seem to be working ("require" not defined), and it also isn't catching my definition files as defined in the files attribute in tsconfig.json.

My failed attempt to solve this:

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()]

This results in Syntastic spitting out to me this error:

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

This is probably because it's running a command like tsc -p /path/to/project/ app.ts, which is an illegal use of that flag... But I don't understand why my settings in tsconfig.json are being ignored by syntastic :(

like image 398
osdiab Avatar asked Dec 05 '15 06:12

osdiab


2 Answers

Summary

Add let g:syntastic_typescript_tsc_fname = '' to .vimrc.

Details

As romainl mentioned in his answer, the "Using tsconfig.json" section of the Typescript wiki states:

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.

You can do this in Vim using Syntastic by adding the following to your .vimrc, or .vimrc.after if you use Janus, as found in LCD 047's answer to your Syntastic issue #1628:

let g:syntastic_typescript_tsc_fname = ''
like image 61
Matthew Rankin Avatar answered Oct 29 '22 01:10

Matthew Rankin


The wiki says:

Using tsconfig.json

  • 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.

  • By invoking tsc with no input files and a -project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

When input files are specified on the command line, tsconfig.json files are ignored.

So, basically, you need to find a way to tell Syntastic to not pass the filename to tsc.

I'd suggest using their issue tracker from now on.

like image 2
romainl Avatar answered Oct 29 '22 01:10

romainl