TypeScript quick reference
TypeScript 7 in strict mode on Node.js 22: type annotations and inference, unions and narrowing, interfaces and generics, typed collections, async code, input and files — and how type-checking and running work in Zerethon IDE.
Written for TypeScript 7. Examples that show an output were run in the Zerethon sandbox (TypeScript 7) on 2026-10-20.
Basics
-
Hello, World
The smallest TypeScript program: it is type-checked, compiled to JavaScript and run with Node.js.
-
Types, inference and unions
Annotate variables, let TypeScript infer the rest, and combine types with unions and literal types.
-
Conditions, loops and narrowing
if,switch,for…ofandwhile, and how a check narrows a union type. -
Functions
Typed parameters and return values, optional and default parameters, and function types.
-
Interfaces, classes and generics
Describe object shapes with
interfaceandtype, write classes, and reuse code for any type with generics.
Data
-
Arrays, tuples, Record and Map
Typed arrays, tuples,
Recordfor dictionaries,MapandSet, and sorting. -
Strings and regular expressions
Template literals, string methods and regular expressions — the same as JavaScript, with types.
-
Promises and async / await
Type asynchronous functions as
Promise<T>and wait for them withawait.
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with Node's
fsmodule. -
Reading and writing files
Read project files with
fs, parse JSON into a typed shape, and write temporary files under/tmp. -
Modules and several files
Split a program into
.tsfiles withimportandexport; no npm packages.
In Zerethon IDE
-
Running TypeScript in Zerethon IDE
How Run type-checks, compiles and runs your project, the time limit, input and tests.
-
Common errors
The type errors you meet first (
TS2304,TS2322,TS18048,TS7006,TS2339,TS2451) and run-time errors. -
Official documentation
Where to read more: the TypeScript Handbook, the TSConfig reference, and MDN / Node.js for the JavaScript underneath.