Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Support for Visual Studio 2017

Tags:

I have recently been trying to learn TypeScript, and in some of the videos I have been watching after installing the 'Web Essentials' extension when working with a .ts file visual studio gives you a pre-view panel so you can see the JavaScript as you type.

These videos seem to be using VS 2012.

However installing Web Essentials on VS 2017 doesn't seem to have this option, does anyone know how I can get this to work in VS 2017? Does it have the same support for TypeScript?

like image 740
Ayo Adesina Avatar asked Mar 31 '17 21:03

Ayo Adesina


People also ask

Does Visual Studio support TypeScript?

TypeScript supportBy default, Visual Studio 2022 provides language support for JavaScript and TypeScript files to power IntelliSense without any specific project configuration. For compiling TypeScript, Visual Studio gives you the flexibility to choose which version of TypeScript to use on a per-project basis.

How do I know if TypeScript is installed in Visual Studio 2017?

TypeScript is installed through the NPM package manager. The -g means it's installed on your system globally so that the TypeScript compiler can be used in any of your projects. Test that the TypeScript is installed correctly by typing tsc -v into your terminal or command prompt.


1 Answers

So TypeScript is installed by default with VS2017 (Update 2 will give you the latest version of 2.3 and allow side by side installs). If you don't have it you can add it via the Visual Studio Installer - from the installer click the burger menu and choose Modify, then click Individual Components and under SDKs, Libraries and Frameworks you can add TypeScript.

Once installed you can add a tsconfig.json file to tell the TypeScript compiler how to behave, example here:

{     "compileOnSave": true,     "compilerOptions":     {         "noImplicitAny": false,         "noEmitOnError": true,         "removeComments": false,         "sourceMap": true,         "target": "es5"     },     "exclude":     [         "node_modules"     ] } 

The important setting is compileOnSave which tells VS to compile the js file when you save the ts.

You should now see you have a nested Javascript file within your TypeScript file:

Nested TypeScript

Now you just need to open both files side by side and when you save the ts then js will automatically update (it helps to tick the always update option if VS prompts you to load the changed file on disk).

like image 159
Matt Avatar answered Sep 28 '22 01:09

Matt