TypeScript Tutorial
TypeScript Get Started
Install tsc locally, or use the StudyGrid TypeScript editor. Either way you need a .ts file and a first console.log.
Two ways to run TypeScript
You can compile in the browser on StudyGrid, or install a compiler on your computer. The language is the same. The editor is faster for lessons. A local compiler is what you use for real projects.
The StudyGrid compiler is /typescript/try. Click Try it in TypeScript under an example. Python stays at /try. C++ stays at /cpp/try. HTML stays at/html/try. TypeScript examples never open those three.
Use the StudyGrid editor
- Open a chapter and copy an example, or go straight to Try TypeScript.
- Press Compile & run (or Ctrl + Enter).
- Read the build log. If tsc is unhappy, the program does not run.
- Read program output underneath. That is what
console.logprinted.
If the program uses readLine(), type values in the stdin box on the left, then compile again. That box is not a popup and not a C++ cin prompt.
Install a compiler (optional)
Local TypeScript needs Node.js so you can run npx tsc. You do not have to install tsc globally.npx downloads and runs the compiler when you call it.
| System | Typical setup |
|---|---|
| Windows | Install Node.js LTS from nodejs.org. Confirm with node --version in PowerShell. |
| macOS | Node.js LTS, or brew install node. Then the same node --version check. |
| Linux | Install Node.js from the package manager or the NodeSource setup, then check node --version. |
Check the compiler with npx tsc --version. You want a 5.x line. StudyGrid uses a current tsc in the browser, so lesson code does not depend on a special local version.
Compile a file locally
Save this as main.ts. It is a complete program. There is no main function.
Example
const message: string = "Compiled locally";
console.log(message);Then in a terminal in that folder run npx tsc --strict main.ts. That writes main.js. Run the JavaScript with node main.js. On StudyGrid, Compile & run does both steps for you.
Change message to another string and compile again. If tsc prints a type error, fix that first. Later messages are often fallout from the first mistake.
What you need in every file
- A
.tsname, not.txtand not.cpp. - No required include.
console.logis built in, unlike C++cout. - No
main. The file runs from the top, like a script. - A semicolon at the end of each statement.
Example
const year: number = 2026;
const ready: boolean = true;
console.log("Year:", year);
console.log("Ready:", ready);If tsc prints a wall of errors, start at the first error. A missing semicolon or a wrong type on line 1 often causes a chain of messages below it.
Download from a lesson
Every example has Download .ts. Save the file, compile it with tsc, and compare the result with the browser editor. Next: the syntax rules the compiler enforces.