Magento 2 Experten — Hyvä Theme, Tailwind CSS & SEO aus einer Hand ›

Creating Your First TypeScript Project

Your First TypeScript Project

~12 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026

Now let's set up the actual TypeScript configuration and write the first, runnable file of our library management project.

Creating tsconfig.json

tsconfig.json controls HOW TypeScript checks and compiles our code – the central configuration file of every TypeScript project. Instead of writing it by hand, let's have it generated:

npx tsc --init

This produces a tsconfig.json with MANY commented-out options as documentation. We'll replace it with a lean, deliberately chosen configuration:

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "outDir": "dist",
    "rootDir": "src",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"]
}

The key options in detail

  • "target": "ES2022" – up to which JavaScript version TypeScript is allowed to "downlevel" the code when compiling. Newer Node.js versions support ES2022 natively, so there's no reason to fall back to older syntax.
  • "module"/"moduleResolution": "NodeNext" – matches our "type": "module" from package.json (chapter 2), uses modern ES module resolution instead of the older CommonJS system.
  • "outDir"/"rootDir" – determine WHERE compiled .js files end up (dist/) and WHERE TypeScript source files are read from (src/) – important for npm run build from chapter 2.
  • "strict": true – enables ALL strict type checks at once (including strictNullChecks, noImplicitAny) – ALWAYS recommended for a NEW project, we'll build on this throughout the tutorial.
  • "skipLibCheck": true – skips type-checking .d.ts files in node_modules – considerably faster compilation, without risking type errors in THIRD-PARTY libraries.

src/index.ts: the first file

src/index.ts
console.log('Welcome to the library management system!');
npm start

npm start (or tsx src/index.ts directly) prints "Welcome to the library management system!" to the console – tsx transparently compiles the file in the background, with no .js file ever visibly appearing anywhere.

Provoking a deliberate error

To see strict: true in action, add this line as a test:

let bookCount: number = 42;
bookCount = 'forty-two'; // error!

Your editor underlines 'forty-two' in RED: "Type 'string' is not assignable to type 'number'." – EXACTLY the moment we discussed conceptually in chapter 1, now live in your own project. Remove the broken line again before moving on.

This project's target structure

Current state after this chapter – grows considerably over the coming chapters

bibliotheks-app/
├── package.json
├── tsconfig.json
└── src/
    └── index.ts

Tipp: npm run typecheck (from chapter 2) is now your most important command for checking the ENTIRE project's type status, regardless of which single file you're currently editing – use it regularly, especially before larger refactors.