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

  1. Open a chapter and copy an example, or go straight to Try TypeScript.
  2. Press Compile & run (or Ctrl + Enter).
  3. Read the build log. If tsc is unhappy, the program does not run.
  4. Read program output underneath. That is what console.log printed.

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.

SystemTypical setup
WindowsInstall Node.js LTS from nodejs.org. Confirm with node --version in PowerShell.
macOSNode.js LTS, or brew install node. Then the same node --version check.
LinuxInstall 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 .ts name, not .txt and not .cpp.
  • No required include. console.log is 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.

FAQ: TypeScript Get Started

Common questions about this page.

What is the StudyGrid TypeScript tutorial?

The StudyGrid TypeScript tutorial follows the same chapter rhythm as C++: syntax, types, input, loops, functions, classes, generics, maps, and lambdas. Each chapter has copy-and-run examples.

Should I run typescript get started examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn typescript get started in this TypeScript TypeScript lesson (TypeScript Get Started).

Is the TypeScript editor the same as Try Python or Try C++?

No. Try TypeScript type-checks with tsc at /typescript/try and shows stdout plus compiler messages. Try Python stays at /try. Try C++ stays at /cpp/try. TypeScript lessons never open those editors.

Do I need to install a compiler to learn TypeScript?

No. Open a chapter, click Try it in TypeScript, and compile in the browser. You can also download a .ts file and compile locally with tsc.

Where should I start the TypeScript tutorial?

Start at TypeScript Intro, then Get Started and Syntax. After the first program, continue to output, variables, and if-else. After classes, open TypeScript Examples, then generics, Map, and arrow functions. Use Next at the bottom of each chapter.

Is the TypeScript tutorial free?

Yes. The TypeScript workshop on StudyGrid (studygrid.in) is free: dashboard, chapters, and the compile-and-run editor.