Welcome to the most practical, hands-on TypeScript tutorial for MIMUW students.
Every chapter is a .ts file you can read, run, and edit.
No fluff—just the stuff you’ll actually use.
npm install
After running npm install, you might see npm fund—this is just info about open source support; you can ignore it.
npm install zod
If not, comment out or remove the Zod section in 10_api_and_error_handling.ts.
09_react.tsx):
npm install react react-dom
npm install --save-dev @types/react @types/react-dom
npm install --save-dev typescript@latest
tsconfig.json (compilerOptions section):
{
"jsx": "react-jsx"
}
"jsx": "react" instead (but upgrading is strongly recommended).You can’t run React
.tsxfiles withts-nodein Node.js.
These are meant for use in a real React project (e.g., Vite, Create React App, Next.js).If you see:
TS17004: Cannot use JSX unless the '--jsx' flag is provided.→ Add/adjust the
"jsx"option intsconfig.jsonas shown above.TS2307: Cannot find module 'react' or its corresponding type declarations.→ Make sure you installed both
react,react-dom, and their@typespackages.
05_modules.ts requires a separate mathUtils.ts file in the same directory..ts file.├── 05_modules.ts
├── mathUtils.ts
npx ts-node 01_basics.ts
You can debug your TypeScript code directly with ts-node and source maps.
tsconfig.json:
{
"compilerOptions": {
"sourceMap": true
}
}
{
"type": "node",
"request": "launch",
"name": "Debug TS with ts-node",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${file}"],
"skipFiles": ["<node_internals>/**"]
}
node --inspect-brk -r ts-node/register 03_functions.ts
Then, attach your VSCode debugger or open chrome://inspect in Chrome.
01_basics.ts02_types.ts03_functions.ts04_classes.ts05_modules.tsmathUtils.ts in the same directory)06_async.ts07_tips_tricks.ts08_realworld_examples.ts09_react.tsx10_api_and_error_handling.ts11_antipatterns.tsQ: Do I need to read every file in order?
A: No. Jump to the topic you need, or come back when you hit problems.
Q: How do I run code?
A: Use ts-node. Example:
npx ts-node 04_classes.ts
Q: I get TS2307: Cannot find module 'zod'?
A: Run npm install zod or comment out the Zod usage.
Q: I get TS2307: Cannot find module 'react' or its corresponding type declarations.?
A: Run:
npm install react react-dom
npm install --save-dev @types/react @types/react-dom
Q: I get TS17004: Cannot use JSX unless the '--jsx' flag is provided.?
A: Add/adjust "jsx": "react-jsx" in your tsconfig.json’s "compilerOptions".
If your TypeScript is older than 4.1, upgrade it or use "jsx": "react".
Q: How do modules work in Chapter 5?
A: Use two files: mathUtils.ts (exports) and 05_modules.ts (imports/usage).
Never import from the same file you export in.
Q: TypeScript can’t find my module or import path?
A: Double-check your import paths (relative, such as ./mathUtils).
If you move files around, update the import paths accordingly.
If using custom paths, set up baseUrl and paths in your tsconfig.json.
Q: My code changes aren’t showing up?
A: If you’re running compiled JS, make sure to re-run tsc or use ts-node directly on the TypeScript file to see changes instantly.
Q: How do I debug TypeScript code?
A: See the “Debugging TypeScript” section above for using source maps and debugging with VSCode or Node.js.
Q: Why does my import look like it works in VSCode, but fails in the terminal?
A: VSCode may resolve modules differently.
Always use relative paths unless you’ve set up custom module resolution in tsconfig.json.
import { add } from './mathUtils'tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["*", "src/*"]
}
}
}
npx tsc --traceResolution to debug how TypeScript resolves your imports.