TypeScript 5 Overview
TypeScript 5 is a major release with significant performance improvements and new features. It includes faster build speeds, new decorator syntax, and enhanced type system.
Official Decorator Support
New decorator syntax compliant with the ECMAScript decorator proposal (Stage 3) is now available.
function logged(originalMethod: any, context: ClassMethodDecoratorContext) {
const methodName = String(context.name);
return function (this: any, ...args: any[]) {
console.log(`Calling ${methodName} with`, args);
const result = originalMethod.call(this, ...args);
console.log(`${methodName} returned`, result);
return result;
};
}
class Calculator {
@logged
add(a: number, b: number): number {
return a + b;
}
}
Difference from before: The
experimentalDecoratorsflag is no longer required, and you can use the new standard decorators.
const Type Parameters
Literal types can now be inferred more easily.
// Traditional
function getConfig<T extends readonly string[]>(items: T): T {
return items;
}
const config = getConfig(['a', 'b', 'c'] as const);
// TypeScript 5
function getConfig<const T extends readonly string[]>(items: T): T {
return items;
}
const config = getConfig(['a', 'b', 'c']); // No need for as const
// Type: readonly ['a', 'b', 'c']
Performance Improvements
TypeScript 5 achieves significant speedup through internal structure optimization.
| Item | Improvement |
|---|---|
| Build Speed | 10-25% faster |
| Package Size | ~50% reduction |
| Memory Usage | Reduced |
Other New Features
All Enums as Union Types
enum Color {
Red,
Green,
Blue
}
// Color type is treated as Color.Red | Color.Green | Color.Blue
moduleResolution: bundler
A new module resolution strategy for modern bundlers has been added.
{
"compilerOptions": {
"moduleResolution": "bundler"
}
}
Migration Points
target: ES2022or later is recommended- Consider migrating to new decorators
- Utilize
moduleResolution: bundler
Summary
TypeScript 5 is a release that achieves both improved developer experience and performance improvements. With the new decorator syntax and const type parameters, you can write more type-safe and expressive code.
← Back to list