Migrating from RxJS v6 to v7
RxJS v7 includes significant improvements to performance, bundle size, and type safety. This guide will help you migrate your application from RxJS v6 to v7.Prerequisites
The rxjs-compat package is not available for v7. You’ll need to address all deprecations before upgrading.
Major Changes Overview
Type System Improvements
RxJS v7 significantly improves TypeScript type inference. Most generic signatures have changed to provide better type inference:Operators with changed generic signatures
Operators with changed generic signatures
The following operators have updated generic signatures. Do not explicitly pass generics - let TypeScript infer them:
combineLatest,concat,merge,race,zipforkJoin,partition,bindCallbackdefer,iif,onErrorResumeNextof,pairs,pipe- All combination operators:
concatAll,mergeAll,switchAll
Promise Conversion Changes
ThetoPromise() method is deprecated in favor of two new, more explicit functions:
Using default values with firstValueFrom and lastValueFrom
Using default values with firstValueFrom and lastValueFrom
Subscription Changes
TheSubscription.add() method now returns void instead of a Subscription:
Observable Internal Changes
Several internal implementation details are no longer exposed:New Features
Animation Frames
A new creation function for working with animation frames:Global Error Handling
Configure global error handlers using the newconfig object:
Enhanced Input Types
RxJS v7 expandsObservableInput to accept more types:
Improved Operators
timeout - Enhanced configuration
timeout - Enhanced configuration
share - Full configuration support
share - Full configuration support
New Combination Operators
To avoid naming conflicts with deprecated operators, new variants were added:Migration Checklist
Remove Generic Type Arguments
Remove explicit generic type arguments from operators like
combineLatest, merge, zip, etc. Let TypeScript infer types automatically.Replace toPromise()
Replace all uses of
toPromise() with firstValueFrom() or lastValueFrom():- Use
firstValueFrom()when you want the first emitted value - Use
lastValueFrom()when you want the final emitted value
Update Subscription Handling
If you relied on
Subscription.add() returning a subscription, refactor to use the remove() method with the same teardown reference.Address Custom Operators
If you created custom operators using
lift, refactor them to use the documented pattern with new Observable().Test Error Handling
Review error handling logic - unhandled errors now throw in their own call stack instead of using
console.warn.Next Steps
For detailed information about specific changes:- Breaking Changes - Complete list of breaking changes
- Deprecations - Deprecated APIs and migration paths
- Operator Reference - Updated operator documentation
