The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Combination operators: concat, startWith

Combination operators: concat, startWith

6:22
Some Observables may complete, and we may want to append another Observable to the one which just completed. This lesson teaches you how to use the concat() operator for either appending or prepending, and how the shortcut operator startWith() is an easy way of prepending values to an Observable.
Watch this lesson now
Avatar
egghead.io

Some Observables may complete, and we may want to append another Observable to the one which just completed. This lesson teaches you how to use the concat() operator for either appending or prepending, and how the shortcut operator startWith() is an easy way of prepending values to an Observable.

Avatar
Jon

var bar = foo.startWith('a'); gives me a TypeScript compile error:
Argument of type 'string' is not assignable to parameter of type 'number | Scheduler'.

However, changing it to var bar = foo.startWith(1); gives me no such error. Thoughts?

Avatar
Andre

Hi Jon. With TypeScript, you would need to declare foo as Observable, because otherwise it will infer that foo has type Observable and we can't pretend a string is a number. Observable means "this observable may emit either strings or numbers".

In reply to Jon
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?