TypeScript 5.7 Released - What’s New and What You Need to Know
The TypeScript team has released version 5.7, bringing several developer-friendly features and performance improvements. Let’s dive into the most important updates.
🎯 Key Highlights
- Path rewriting for relative imports
readonlytype modifier for mapped types- Improved type inference for
Promise.withResolvers() - Faster compilation times (up to 15% improvement)
- Enhanced error messages
1. Path Rewriting for Relative Imports
One of the most requested features is now here! TypeScript 5.7 can now rewrite relative import paths when compiling.
Before (TypeScript 5.6)
// src/utils/helpers.ts
export function formatDate(date: Date) { ... }
// src/components/DateDisplay.tsx
import { formatDate } from '../utils/helpers';
// Emitted as: import { formatDate } from '../utils/helpers';
Now (TypeScript 5.7)
// tsconfig.json
{
"compilerOptions": {
"module": "NodeNext",
"rewriteRelativeImportExtensions": true
}
}
// Now your imports are rewritten correctly!
import { formatDate } from '../utils/helpers';
// Emitted as: import { formatDate } from '../utils/helpers.js';
Why this matters: No more runtime errors due to missing .js extensions in ESM projects!
2. readonly Modifier for Mapped Types
TypeScript 5.7 introduces more granular control over readonly in mapped types.
type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
type ReadonlyUser = {
readonly id: number;
readonly name: string;
email: string;
};
type MutableUser = Mutable<ReadonlyUser>;
// Result: { id: number; name: string; email: string; }
Use cases:
- Creating mutable versions of readonly types
- Building flexible utility types
- Framework and library development
3. Better Type Inference for Promise.withResolvers()
The new Promise.withResolvers() API (Stage 3) now has proper type inference.
// Before: Had to manually specify types
const { promise, resolve, reject } =
Promise.withResolvers<number>();
// Now: Types are automatically inferred!
const { promise, resolve, reject } =
Promise.withResolvers<User>();
resolve({ id: 1, name: 'Alice' }); // ✅ Works!
resolve('invalid'); // ❌ Type error!
4. Performance Improvements
TypeScript 5.7 brings significant performance gains:
| Metric | Improvement |
|---|---|
| Initial compilation | 10-15% faster |
| Incremental builds | 8-12% faster |
| Type checking | 5-10% faster |
| Memory usage | Reduced by ~7% |
Real-world impact: For a medium-sized project (1000+ files), you can save 2-5 seconds on each build.
5. Enhanced Error Messages
Error messages are now more helpful and actionable.
Before (TypeScript 5.6)
const user = { name: 'Alice' };
user.age = 25; // Error: Property 'age' does not exist on type '{ name: string; }'
Now (TypeScript 5.7)
const user = { name: 'Alice' };
user.age = 25;
// Error: Property 'age' does not exist on type '{ name: string; }'.
// Did you mean to include it in the object literal?
// Suggestion: const user = { name: 'Alice', age: 25 };
6. Other Notable Changes
Stricter this Parameter Checks
function greet(this: { name: string }) {
console.log(`Hello, ${this.name}`);
}
greet(); // ❌ Error: The 'this' context is not assignable
greet.call({ name: 'Alice' }); // ✅ Works!
Improved JSDoc Support
/**
* @param {string} name - User's name
* @param {number} [age] - User's age (optional)
* @returns {User} User object
*/
function createUser(name, age) {
return { name, age: age ?? 0 };
}
TypeScript now provides better intellisense and type checking for JSDoc annotations.
Breaking Changes ⚠️
While TypeScript maintains backward compatibility, there are a few minor breaking changes:
- Stricter
nevertype checking - Some edge cases now correctly resolve tonever --moduleResolution bundler- Behavior changes for certain import patterns- Generic constraint inference - More accurate but may cause new errors in edge cases
Migration tip: Most codebases won’t be affected. Run tsc --noEmit to check for issues before upgrading.
How to Upgrade
npm
npm install -D typescript@5.7
yarn
yarn add -D typescript@5.7
pnpm
pnpm add -D typescript@5.7
Should You Upgrade?
Yes, if:
- You’re using ESM with Node.js
- You need better performance on large codebases
- You want improved error messages
Wait, if:
- You’re on a legacy project with complex build setup
- You use heavily customized tooling that might need updates
What’s Next?
The TypeScript team is already working on TypeScript 5.8 (expected Q2 2026) with these potential features:
- Type-safe environment variables
- Enhanced template literal types
- Better support for decorators
- Improved watch mode performance
Resources
Conclusion
TypeScript 5.7 is a solid release focused on developer experience and performance. The path rewriting feature alone makes it worth upgrading for modern Node.js projects.
Recommendation: Upgrade to 5.7 for new projects immediately. For existing projects, test thoroughly before upgrading production dependencies.
Happy coding! 🚀