TypeScript 5 Features You Should Actually Use
TypeScript 5 shipped with a lot of features. Here are the ones that actually matter for your daily work.
1. const Type Parameters
Before TS5, getting literal types required awkward workarounds:
typescript// Before: Types get widened function getRoutes<T extends readonly string[]>(routes: T) { return routes; } const routes = getRoutes(["home", "about"]); // string[] // After: Use const modifier function getRoutes<const T extends readonly string[]>(routes: T) { return routes; } const routes = getRoutes(["home", "about"]); // readonly ["home", "about"]
This is huge for type-safe routing, configuration objects, and constants.
2. Decorators (Finally Standardized)
typescriptfunction logged(target: any, context: ClassMethodDecoratorContext) { return function (...args: any[]) { console.log(`Calling ${String(context.name)}`); return target.apply(this, args); }; } class UserService { @logged async getUser(id: string) { return db.users.find(id); } }
No more experimentalDecorators flag needed.
3. satisfies + as const
The killer combo:
typescriptconst config = { apiUrl: "https://api.example.com", timeout: 5000, retries: 3, } as const satisfies Config; // config.apiUrl is "https://api.example.com" (literal) // But TypeScript still validates it matches Config
4. Improved Enums
typescriptenum Status { Pending = "pending", Active = "active", Closed = "closed", } // Now works correctly in unions type StatusOrString = Status | string;
5. Better Bundle Size
TS5's new emit is 10-15% smaller. For large projects, this adds up.
Migration Tips
- Update your tsconfig.json target to ES2022+
- Remove experimentalDecorators if using new decorators
- Review any code that relied on enum quirks
What I Skip
- Bundler resolution mode (too many edge cases)
--verbatimModuleSyntax(breaks too many libraries)
Stick with the features that have clear benefits and minimal migration cost.