Set Up Your Language · 4 of 14
Setting Up TypeScript
TypeScript is JavaScript plus types: labels that say what kind of value something holds, such as text or a number. The TypeScript checker reads those labels and warns you about mistakes before the program runs. It is made by Microsoft and used for most large web applications. TypeScript runs on Node.js, so you install Node.js first, then TypeScript itself.
New to all this? Read Before you start on the main page first: it shows how to open Terminal, make a folder for your code, and see file name endings. It takes five minutes and prevents most problems.
1 What to download, and from where
Download only from typescriptlang.org, the official TypeScript website (TypeScript itself is downloaded through npm, which comes with Node.js). Other download sites can bundle unwanted software.
- First install Node.js by following the JavaScript (Node.js) set-up page, up to and including the version check.
- TypeScript itself is downloaded with npm, the add-on tool that came with Node.js. The official instructions are at typescriptlang.org/download.
2 Install it on Windows
- Open Terminal.
- Type this line and press Enter:
npm install -g typescript-gmeans "global": install it for the whole computer, not just one folder. - Wait until you see a line like
added 1 package in 3s.
3 Check that it worked
Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. Then type this and press Enter:
tsc --versionWhat you will see: The word Version and a number. tsc stands for TypeScript Compiler, the checker and translator.
Version 5.9.3
If you see an error such as "is not recognized" instead, look at the common mistakes at the bottom of this page.
4 Write and save your first program
A program is just a text file. You can write it in Notepad, which comes with Windows. (Later you may like the free Visual Studio Code editor from code.visualstudio.com, which colours the code and helps spot mistakes.)
- Open Notepad (press the Windows key, type Notepad, press Enter).
- Type the program below, or click Copy and paste it in with Ctrl + V. Every symbol matters, so copy it exactly.
const message: string = "Hello, World!"; console.log(message); - In Notepad choose File → Save as. Go to your
C:\codefolder. Set Save as type to All files (*.*), type the file namehello.tsexactly as shown, including the dot and the ending, and click Save.
The first line makes a box named message; : string is the TypeScript label saying it holds text. The second line prints it.
Do not use Word. Word saves extra formatting and changes straight quotes " into curly ones “ ”, which no programming language accepts.
5 Run it and see the result
TypeScript is checked and turned into plain JavaScript first, then Node.js runs that.
Open File Explorer, go into your C:\code folder, right-click an empty part of the window and choose Open in Terminal. (More ways to open Terminal.) If Terminal was already open from the check above and is in another folder, type cd C:\code and press Enter.
Type these lines one at a time, pressing Enter after each:
tsc hello.ts
node hello.jsWhat you will see: the words below on a new line. That is your program running.
Hello, World!
The first command creates a new file, hello.js, next to yours. Shortcut: newer Node.js versions can also run the file directly with node hello.ts, but that skips the checking, which is the point of TypeScript.
Congratulations: you have written and run a TypeScript program.
6 Common beginner mistakes and how to fix them
Error messages look alarming but are usually precise: read the first line, and look for a line number. If you are stuck, copy the whole error message and paste it into an AI assistant along with your code, and ask what it means.
tsc : File C:\...\tsc.ps1 cannot be loaded because running scripts is disabled on this system
Why: PowerShell, the program inside Terminal, blocks scripts by default, and tsc is installed as one.
Fix: type this once and press Enter, then try again:
Set-ExecutionPolicy -Scope CurrentUser RemoteSignedtsc.cmd instead of tsc.) The same fix works for npm if it shows this error.error TS2322: Type 'number' is not assignable to type 'string'
Why: this is TypeScript doing its job: the label says text, but the value is a number, for example const message: string = 42;.
Fix: make the value match the label (put the text in quotes), or change the label to number.
'tsc' is not recognized as an internal or external command
Why: Windows cannot find the program. Either the Terminal was open before you installed it, or the program's folder is not on the PATH (the list of folders Windows searches for commands).
Fix: Close every Terminal window you have open and open a new one. A Terminal that was already open does not know about programs installed after it started. If it still fails, restart the computer, then check the folder is on the PATH (how to check and add it). Also check that npm install -g typescript finished without red error lines.