rxjs / 7.5.5 / api / operators / startwith.html /

startWith

function deprecated operator

Deprecation Notes

The scheduler parameter will be removed in v8. Use scheduled and concatAll. Details: https://rxjs.dev/deprecations/scheduler-argument

startWith<T, A extends readonly, unknown>()

Parameters

There are no parameters.

Overloads

startWith(value: null): OperatorFunction<T, T | null>

Parameters

value null

Returns

OperatorFunction<T, T | null>

startWith(value: undefined): OperatorFunction<T, T | undefined>

Parameters

value undefined

Returns

OperatorFunction<T, T | undefined>

startWith()

Parameters

There are no parameters.

startWith(...values: D[]): OperatorFunction<T, T | D>

Returns an observable that, at the moment of subscription, will synchronously emit all values provided to this operator, then subscribe to the source and mirror all of its emissions to subscribers.

Parameters

values D[]

Items you want the modified Observable to emit first.

Returns

OperatorFunction<T, T | D>: A function that returns an Observable that synchronously emits provided values before subscribing to the source Observable.

This is a useful way to know when subscription has occurred on an existing observable.

First emits its arguments in order, and then any emissions from the source.

startWith marble diagram

Examples

Emit a value when a timer starts.

import { timer, map, startWith } from 'rxjs';

timer(1000)
  .pipe(
    map(() => 'timer emit'),
    startWith('timer start')
  )
  .subscribe(x => console.log(x));

// results:
// 'timer start'
// 'timer emit'

© 2015–2022 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/startWith