TypeScript 5.x introduces major language improvements, standard ECMAScript decorators, const type parameters, faster build speeds, smaller package sizes, and flexible moduleResolution: "bundler" configurations.
const Type Parameters: Preserves literal types in generic inference without requiring as const at call sites.tsconfig Extends: tsconfig.json can now inherit from an array of base configs ("extends": ["./config/base", "./config/strict"]).moduleResolution: "bundler": Tailored resolution for modern web bundlers like Vite, esbuild, and Webpack.// const Type Parameters (TS 5.0+)
// Without const T: inferred as string[]
// With const T: inferred as readonly ["red", "green", "blue"]
function setPalette<const T extends readonly string[]>(colors: T): T {
return colors;
}
const palette = setPalette(["red", "green", "blue"]);
// palette type is explicitly readonly ["red", "green", "blue"], not string[]
// Modern TS 5 Decorator Example
function LogExecution(target: any, context: ClassMethodDecoratorContext) {
const methodName = String(context.name);
return function (this: any, ...args: any[]) {
console.log(`[LOG] Calling method ${methodName} with args:`, args);
return target.apply(this, args);
};
}
class OrderService {
@LogExecution
public placeOrder(orderId: string, amount: number) {
return { success: true, orderId, amount };
}
}
const service = new OrderService();
service.placeOrder("ORD-551", 299.99);
moduleResolution: "bundler" for Vite Projects: Ensures accurate import path resolution matching bundler behavior.const Generic Constraints: Simplifies literal tuple and object inference without cluttering code with as const."target": "ES2022" or higher to fully leverage native TS 5 features.What modifier is added to generic parameters in TypeScript 5 to infer literal types automatically? (Answer: const)
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With