TypeScript 5.0 was released in May 2023 bringing several highly anticipated features. Let’s explore what changed and why it matters.
Decorators
Decorators have finally stabilized. You can now use them without the experimental flag:
function log(target: any, propertyKey: string) {
const original = target[propertyKey];
target[propertyKey] = function(...args: any[]) {
console.log(`[${propertyKey}] ${JSON.stringify(args)}`);
return original.apply(this, args);
};
}
class Greeter {
@log
greet(name: string): string {
return `Hello, ${name}`;
}
}
Const Type Parameters
The const modifier on type parameters lets you preserve exact types instead of widening:
function createCollection<const T extends readonly unknown[]>(items: T) {
return { items };
}
const col = createCollection(['a', 'b', 1, true]);
// Inferred as ['a', 'b', 1, true] — not string[] | number[] | boolean[]
Improved Autosorting in enums
When you use the auto modifier on enum members, TypeScript now handles numeric auto-increment more intuitively when mixed with explicit values.
Summary
These improvements make TypeScript feel more modern while maintaining backward compatibility. If you’re on an older version, plan your migration path carefully and test decorators thoroughly before full adoption.