DeveloperBreeze

Code Maintainability Development Tutorials, Guides & Insights

Unlock 1+ expert-curated code maintainability tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your code maintainability skills on DeveloperBreeze.

Advanced TypeScript: Type Inference and Advanced Types

Tutorial August 05, 2024
typescript

type Readonly<T> = {
  readonly [K in keyof T]: T[K];
};

interface Car {
  make: string;
  model: string;
  year: number;
}

const myCar: Readonly<Car> = {
  make: 'Toyota',
  model: 'Corolla',
  year: 2020
};

// myCar.make = 'Honda'; // error
type IsString<T> = T extends string ? 'string' : 'not string';

type Test1 = IsString<string>; // 'string'
type Test2 = IsString<number>; // 'not string'