Skip to content

Unexpected startWith types behaviour inside pipe #4013

Description

@OliverJAsh

Bug Report

Current Behavior
When using startWith inside of pipe, the argument type is not validated and/or the return type may be incorrect.

Reproduction

import { of } from 'rxjs';
import { startWith } from 'rxjs/operators';
import 'rxjs/Rx';

const ob2$ = of(1).startWith(
    // Expect error, got one :-)
    // Argument of type '"foo"' is not assignable to parameter of type 'number | SchedulerLike'.
    'foo',
);

const ob$ = of(1).pipe(
    startWith(
        // Expected error, but got none :-(
        'foo',
    ),
);
// OR, if we don't get an error, we should at least get a union:
// $ExpectType Observable<number | string>
// but got actual type Observable<{}>
ob$;

Expected behavior
When using startWith inside of pipe, I would expect either:

  • the argument type must match the Observable's inner type
  • the return type should be a union of the Observable's inner type and the argument type

Environment

  • Runtime: no runtime, purely type level
  • RxJS version: 6.2.2

Possible Solution

Additional context/Screenshots
Related #2544

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions