Skip to content

Prepare for RxJS v7  #79751

@spalger

Description

@spalger

RxJS v7 is deprecating the .toPromise() method of observable objects, and fixing the type definition to return Promise<T | undefined> as there is no way for the type system to know if the observable will always produce at least one notification so the resolve value may be undefined in all places where .toPromise() is used (though it's made impossible by using certain operators).

This method is replaced with two helpers:

firstValueFrom(x$: Observable<T>): Promise<T>: equivalent of x$.pipe(first()).toPromise(), resolves with the first value, unsubscribes after the first notification, rejects if o$ completes without any notifications.

lastValueFrom(x$: Observable<T>): Promise<T>: equivalent of x$.pipe(last()).toPromise(), resolves after the observable completes with the last notification value, rejects if o$ completes without any notifications.

We should implement these methods in @kbn/std and start migrating parts of the code base to these helpers. Once RxJS v7 is released we can replace our helpers with the standard ones.

If we can get most or all of the codebase migrated to use the new helpers before RxJS v7 is released then we can use an eslint rule to prevent new usage of toPromise(), or just fixup the remaining issues when the final upgrade happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions