Foundations & Tooling TypeScript 6

03. TypeScript 6 & Strict Engineering

Enforce sound type boundaries, literal type preservation with satisfies, const type parameters, discriminated unions, and strict modular compilation.

typescript.ts
typescript
interface RouteConfig {
path: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
rateLimit?: number;
roles?: readonly ('admin' | 'editor' | 'member')[];
}
// 1. 'satisfies' enforces type safety without widening literal types
export const routeRegistry = {
getUser: { path: '/api/v1/users', method: 'GET' },
createUser: { path: '/api/v1/users', method: 'POST', rateLimit: 60, roles: ['admin'] },
deleteUser: { path: '/api/v1/users/:id', method: 'DELETE', rateLimit: 10 }
} as const satisfies Record<string, RouteConfig>;
// Inferred literal preservation
type CreateMethod = typeof routeRegistry.createUser.method; // Exactly 'POST'
// 2. Const Type Parameters in Generics
function defineEndpoint<const T extends RouteConfig>(config: T): T {
return config;
}
const customEndpoint = defineEndpoint({
path: '/api/v1/analytics',
method: 'GET',
roles: ['admin', 'member']
});

TypeScript 6 & Modern Strict Typing

TypeScript 6 provides sound type inference, const type parameters, the satisfies operator, and strict discriminated unions.

  • The satisfies Operator: Enforces that an expression matches an interface without widening literal string or numeric types to general primitives.
  • Const Type Parameters: Allows generic functions to infer literal tuple and object types automatically at the call site without requiring as const.
  • Discriminated Unions & Exhaustiveness: Guarantees that all variants of an event or state machine are handled safely at compile time.
Discriminated Union Exhaustiveness Visualiser Strict Narrowing
Select Event Variant:
Evaluated Payload:
{
  "type": "LOGIN",
  "userId": "usr_2026",
  "timestamp": 1792350683356
}
Exhaustive Narrowing Output:

[LOGIN] User usr_2026 authenticated at 7:11:23 PM