unraveljs.com
Menu
updates

TypeScript 5.7 Released - What's New and What You Need to Know

TypeScript 5.7 brings path rewriting for relative imports, new type modifiers, and significant performance improvements. Here's everything you need to know.

#typescript #javascript #type-safety #compiler #tooling

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


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:


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:

MetricImprovement
Initial compilation10-15% faster
Incremental builds8-12% faster
Type checking5-10% faster
Memory usageReduced 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:

  1. Stricter never type checking - Some edge cases now correctly resolve to never
  2. --moduleResolution bundler - Behavior changes for certain import patterns
  3. 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:

Wait, if:


What’s Next?

The TypeScript team is already working on TypeScript 5.8 (expected Q2 2026) with these potential features:


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! 🚀