简体   繁体   中英

How to Compile TypeScript (on save) With Errors in Visual Studio

I upgraded to the latest TypeScript recently and have found that the JavaScript is no longer being generated in Visual Studio (2013) if there are any TypeScript type errors. Is there a way to tell TypeScript to ignore type errors? I'm cleaning up a project and would like to work my way through it incrementally.

This might not be the answer you are looking for, but it is the best for your scenario in my opinion: I think you'd be better off using a task runner (such as gulp, grunt, etc) that watches your files and compiles on the fly. It will ignore the IDE and do what you want it to do.

If you're using Visual Studio 2013, you can first install Task Runner . This allows you to run them inside a window in your IDE.

Then you'll want to setup your project using the given task runner of your choice and creating a task for it. Ted Patrick has an example using gulp here . Depending on the size of your project you might want to use TypeScript's incremental compilation features too.

I use that setup in VS13 and I couldn't be happier. Every time I save a TS file it is recompiled (regardless if it's considered valid by the IDE or not) and I see the errors right there. You can see what it looks like in this screenshot , and the VS13 project/task runner script is available on GitHub if you need a reference.

(If you don't want to be hassled with figuring out a task runner, the compiler (tsc.exe) has a -w command line argument that does all the watching too. You could just create a batch file that you fire once and run on the background.)

Even if VS13 has "native" ways to watch and compile a .ts file, I'd definitely recommend using something like this instead. It decouples your project from the IDE and gives you (or anyone else) the ability to easily compile your project from anywhere, as well as also use whatever other tasks you think are necessary when building the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM