_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

The Complete Guide to TypeScript

17. 12. 2021 1 min read intermediate

TypeScript je JavaScript s typy. A to mění všechno.

Proč TypeScript

  • Chyby zachytíte při kompilaci, ne v produkci
  • Lepší IDE podpora (autocomplete, refactoring)
  • Dokumentace v kódu
  • Bezpečnější refactoring

Základní typy

let name: string = “TypeScript”;
let version: number = 5.3;
let active: boolean = true;
let items: string[] = [“a”, “b”];
let tuple: [string, number] = [“age”, 30];

Interfaces & Types

interface User {
id: number;
name: string;
email?: string; // optional
readonly createdAt: Date;
}

type Status = “active” | “inactive” | “banned”;

Generics

function first(arr: T[]): T | undefined {
return arr[0];
}

interface ApiResponse {
data: T;
error?: string;
}

Utility Types

Partial // všechny properties optional
Required // všechny required
Pick
Omit
Record

Enums vs Union Types

// Preferujte union types
type Direction = “north” | “south” | “east” | “west”;

// Enum jen když potřebujete runtime hodnoty
enum HttpStatus { OK = 200, NotFound = 404 }

Strict mode

// tsconfig.json
{ “compilerOptions”: { “strict”: true } }
// Vždy! Bez strict mode ztrácíte polovinu výhod TS.

Pravidlo

Strict mode vždy zapnutý. Vyhněte se “any”. Pokud nevíte typ, použijte “unknown”.

typescriptjavascriptfrontend
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.