With the recent announcement of Visual Studio Code, there have been a lot of questions about how to get started writing TypeScript. In this quickstart, we’ll create a simple TypeScript project. Out of the box, Visual Studio Code supports TypeScript 1.5 beta and using either the node or Visual Studio command-line compilers. For this quickstart, because of its use of the new tsconfig.json feature, we assume you already have TypeScript 1.5 beta installed.
Let’s start by making a new empty folder, MyProject, and opening it in Visual Studio Code. In Window, click “Open Folder”; on OS X, click “Open” and select a folder:
Create a new file by clicking “New FIle” in the MyProject row of the Explore Sidebar:
Enter “tsconfig.json” as the filename
Type { } in the file and hit Ctrl-Space between the braces to trigger completion:
We can configure the project for ES5, AMD modules, and source maps:
Using “New File” again, add a TypeScript file and try writing some code in it:
Before anything else, let’s try compiling with the Ctrl-Shift-B shortcut key. A message appears telling us that we don’t have a task runner enabled for this project yet. Click “Configure Task Runner” to set up a config file:
Remove “HelloWorld.ts” from the “args” array, and add a property called “isShellCommand” with the value ‘true’ in the config file:
While your application is building, you’ll notice an indicator at the bottom left of the screen
The icons show source control status, build indicator (spinning), number of errors, and number of warnings. You can click on the source control, error, and warning indicators for more information.
In the lower right corner, you’ll see the rest of the status bar, showing the cursor position, line endings, language, and smiley. Click the smiley to send us feedback!

Loving it so far! But I wish it could do debugging for web applications and would compile specific files on save instead of requiring a project build.
Looking forward to the updates!
I have Visual Studio Code on my Mac. When I do a build of a TypeScript source file I see the build indicator spinning but the build does not generate the corresponding JavaScript file, and I am completely puzzled as to why this is. I do have a tsconfig.json file and a tasks.json file. The TypeScript file I am using is valid, because when I invoke tsc on the file from the command line, it does generate a JavaScript file. If anyone has any thoughts on this, please email me at richard.fuhr@gmail,com and/or post here.
tsconfig.json is only supported from Typescript v1.5 (currently in beta) as described here github.com/…/tsconfig.json.
I already installed v1.5 and changed the system environments to point to that, however, when I run build in VSC it still runs Typescript v1.0.3. Anyway I can tell VSC to run the v1.5?
It works now. I installed Typescript v1.5 beta from the TS website. Then removed the environment variables pointing to the other Typescript versions existing in my system. I just needed to restart Visual Studio Code to apply the changes, works perfectly now.
Did you forget to mention that you need to add
"args": ["${file}"]
in the build tasks.json file?
@Brian Di Palma: I didn't, I did exactly what the article suggested by leaving the setting "args" as an empty array. As mentioned here github.com/…/tsconfig.json:
"If no "files" property is present in a tsconfig.json, the compiler defaults to including all files in the containing directory and subdirectories. When a "files" property is specified, only those files are included."
It seems that in Linux it currently ships TS 1.4.1 btw.
Very nice IDE, it seems to confuse ES6 as TS and displays ES6 files as full of errors.
@Richard Fuhr – you can debug some of why things aren't working by looking in the output window or by looking at the errors in the bottom left.
It does assume you're using 1.5beta. I'll update the article to mention that.
Once you have 1.5beta, you should be able to follow the steps above. I created a tsconfig.json, Command+Shift+B for a build, configured tasks.json making sure to remove the '.exe' off "command" and making "args" empty.
@Brian Di Palma – ES6 support is something they're working on for an upcoming release.
PS: Just to follow up, I just realized you don't need to edit the ".exe" part off, since that setting is ignored in OS X.
Is there an option to not have the js files appearing in Visual Studio Code explorer while doing TypeScript development ?
And for anyone here who can be interested, you can find the tasks.json if you're using grunt with the typescript compiler here : github.com/…/tasks.json
There is also tslint task run instead of testing and it got issues – parsing not working :/.
(disclaimer: new to grunt, back to typescript, and code done during the WE so…).
I wrote up some of my thoughts on VS Code here, including a workaround for how to make it compile on save by setting up custom keybindings.
abogartz.github.io/…/visual-studio-code-could-be-great-for-typescript
When I try to share this on LinkedIn I see "Microsoft account requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked. To find out whether your browser supports JavaScript, or to allow scripts, see the browser's online help." What's the heck? 🙂
Very helpful article, although I need the resultant .js files (as others here have mentioned). Any ideas?
@shane, the file will be automatically created for you if they are missing with the content from this article in comment 🙂
@Frédéric forjan Thanks for your reply, but the files aren't generated for me…
Wanted to add few complains:
– F12 dev tools in Windows Internet Explorer 11 is built on TypeScript. The experience is sometime "extremely" slow.
– Will be nice to have abstract classes.
– We need sourcemap support in F12 dev tools for CSS superset langauges (Less, Sass, Stylus).
– In CSS view of F12DT, we need freeform multi text selection and pasting! Chrome is the only browser which supports this and I am not the one who will ever admit that WPF is unable to handle those toy mouse events. So pretty please, do something about it.
Thank you for all the work you guys have done (desperately waiting for abstract class support in TypeScript)!
It'd be great to have an option to see a compiled javascript parallel to TS that you have (just like on VS)
@SomeCat: "F12 dev tools in Windows Internet Explorer 11 is built on TypeScript. The experience is sometime "extremely" slow"
You are imagining that TS is somehow making it slow at runtime? How could that happen, given how TS works?
How can I debug the Typescript code?
A note for anyone who has Visual Studio (2013 and maybe other versions?) installed: VS likely added its TypeScript compiler into your PATH. I was banging my head against the wall trying "npm install -g typescript" until I checked my PATH and found "C:Program Files (x86)Microsoft SDKsTypeScript1.0;". After I removed it, "tsc" is running 1.5.0-beta as I expected.
'tsc.exe' is not recognized as an internal or external command,
operable program or batch file.
Where does Code try to execute the tsc.exe program? I have validated that it is in my node under latest. It is also in my program files.
@Rob – debugging isn't in yet, but hopefully will be coming soon
@Michael Schreiber – did you follow the steps of setting "isShellCommand" and taking out the '.exe'? One of the screenshots shows what the tasks.json should look like, and which seemed to work okay when we tested it.
@Jonathan
You shouldn't take out the .exe from tsc. It took me a few hours to figure out why VS code cant compile and generate the js file.
@Vincent Yang – it depends on which TypeScript compiler you have installed. In this article, we assume you're using Node rather than the Visual Studio (since that is already its own IDE). When using Visual Studio Code, you'll need to provide your own TypeScript compiler.
For the Node one, the 'tsc' seems to work better since the command is 'tsc.cmd' rather than 'tsc.exe'.
Since I write both the WCF Service side and the JAVA client side, it is easiest to use WSDL, or whatever it is called these days, to define my complex record structures at the server side, import these definitions to the client side, and I'm away. Makes future changes easy to maintain too. And I don't care at all if the connections is RESTful.
How is this best accomplished in typescript? Will this become more transparent?
Boyd
@Boyd – external type information is given to TypeScript through .d.ts files. You can find out some information here: http://www.typescriptlang.org/Handbook or by looking for DefinitelyTyped
This is the one-stop way of giving additional information to the TypeScript compiler. For other metadata formats, depending on how close they are semantically with TypeScript's type system (which is modeled on JavaScript's runtime type system), you should be able to write tools that can translate between your metadata format and .d.ts files.
How can I avoid "TS5037 Cannot compile external modules unless the –module flag is provided" in VSCode?
For example here:
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/express/express.d.ts" />
import express = require('express');
it errors on the "import" line.
I know I have to pass –module commonjs to tsc to avoid this, but I can't see a way to configure the tsc options. I have tried setting up tsconfig.json with "module": "commonjs", but this doesn't fix it. If I press Ctrl+Shift+B, the error goes away, but then it comes back as soon as I edit the file.
@Keiji – you can see how in the screenshot. You can create a tsconfig.json file, and in there you can specify the kind of module. Here we specify using AMD-style modules:
{
"compilerOptions": {
"target": "ES5",
"module": "amd",
"sourceMap": true
}
}
Hi Jonathan, Thank you for posting such valuable content. I was wondering if you would be interested in reviewing one of Packts books which is related to TypeScript. It would be great if we could get your feedback about the book.
Regards
Odell Dias
Online Marketing Executive
odelld@packtpub.com
Loving Typescript and Visual Studio Code!
This will save me from having to load up full Visual Studio if I only need to make simple ts/less changes!
Several people have noted this already, but make sure you have the correct version of TypeScript installed!
To find the version you are using, open a command window and enter "tsc -v". If you get anything below 1.5, this tutorial will not work.
For example Visual Studio might have installed an older version and added that to path.
Have a look at your path: Right-click My Computer > Properties >Advanced System Settings >Advanced > Environment Variables > System Variables > Path
In your path you should have "C:Program Filesnodejs" and you should NOT have any references to TypeScript or tsc, since these will override the path to the version of TypeScript you installed through nodejs with npm.
After you have removed the old versions of TypeScripts from Path, reboot, and do a "tsc -v" again to make sure it's working.
Thanks for the info – love vs code thus far.
I've got a gulp watch task to do typescript as part of my build – all works fine. I also have a .tsconfig file setup to keep vs code happy (specifically, to disable it from trying to emit js files from my ts files as the gulp watch task will do this. Anyway, all seems to work fine (gulp task and ts generation), except for one annoying issue in VS Code showing an error when using imports.
e.g. in my ts file I have:
import {computedFrom} from 'aurelia-framework'
…
however VS studio has error saying cannot compile modules unless the –module flag is provided; and that it cannot find the module (even though its in tsconfig files section). Also, intellisense doesn't seem to work cause it can't understand the import statement
Also, I can confirm:
a) tsc -v returns 1.5.0-beta (I've installed it both locally and globally via npm and confirmed version via "npm list" command)
b) my tsconfig.json file is as follow:
{
"version": "1.5.0-beta",
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"sourceMap": false,
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": false,
"noLib": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "./wwwroot",
"rootDir": "./wwwroot",
"noEmit": true
},
"filesGlob": [
"./src/**/*.ts",
"./typings/**/*.ts",
"!./node_modules/**/*.ts",
"!./wwwroot/jspm_packages/**/*.ts"
],
"files": [
"./src/app.ts",
"./src/flickr.ts",
"./src/main.ts",
"./typings/aurelia-amd/aurelia-amd.d.ts",
… (etc)
Also, for my gulp task, I'm using gulp-typescript
Any help would be appreciated
It is important to note that the tsconfig.json should be in the root of your working directory and not the directory that contains your *.ts files.
The ts config is in my root directory. Works fine with atom but cant VS code to work… 🙁
Mmm – VS Code working fine for me – yeay! Think what I must have done wrong is open it from the wrong folder location (i.e. need to open folder location that contains the tsconfig.json file.
Build runner works nice too – better than having another console window open…would be nice if I could see color output though but with VS code showing errors as I type, it's not as much of an issue.
Great work guys/gals 🙂
@Adriaan, I see the same issue.
Closing the file with 'x' in the main pane AND under the 'Working Files' and reopening helped.
Maybe also save files before reopen.
Seems like VS Code does not pick up changes in tsconfig.json.
Thanks! Works like a charm!
In your update you list some new features for VS Code, including 'a watching task to compile on save'.
I've followed this example, but no files are compiled on save, only when I type ctrl-shift-b. How do I enable the compile on save feature?
@Bruce – this post should help you I think….
blogs.msmvps.com/…/automatic-compilation-in-vs-code-for-typescript
Image #7: text HelloWorld.ts should be replaced with ${file} for the compilation to work with the current version of VS Code. This will compile the curretly opened file.
This intro is woefully insufficient.
Im Just An Eight Year Old Boy And My mum says im too smart for my own good lol so i installed visual studio code and how do i use it????
Question, why is the “Build” command (ctrl+shift+B) not in any of the MSCode menus? I mean, how would developers new to MSCode find this very important command, without resorting to looking it up on google or stackoverflow?
Nice article. I did the steps whatever you have done in this article but i am getting this error
error TS5001: The current host does not support the ‘–watch’ option.
Watching build tasks has finished.
I have type script Version 1.8.34 installed on windows 10 and below is the task.json file code
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
“version”: “0.1.0”,
“command”: “tsc”,
“isShellCommand”: true,
“args”: [“-w”, “-p”, “.”],
“showOutput”: “silent”,
“isWatching”: true,
“problemMatcher”: “$tsc-watch”
}
q
Defihitely believe that which you stated. Your favorite justification appeared tto be
oon the internet the simplest thiing to be awsre of.
I say to you, I certainly get irked while people consider
worries that they plainly do not know about. You managed to hit the nail upon the top and also defined ouut tthe whle thing without having side-effects
, ppeople can take a signal. Will probably be back to get more.
Thanks
What’s up, after reading this remarkable piece of writing
i am as well happy to share my familiarity here wkth friends.