Skip to content

debounce durationSelector param has incorrect typings #3164

@patsissons

Description

@patsissons

RxJS version:
5.5.3

Code to reproduce:

Observable
  .of('foo')
  .debounce(() => Observable.of('bar').delay(1000))
  .subscribe();

Expected behavior:
no compiler errors

Actual behavior:
error TS2345: Argument of type '() => Observable<string>' is not assignable to parameter of type '(value: string) => SubscribableOrPromise<number>'.

Additional information:
It looks like this was previously just working due to a type checking deficiency that has been corrected (not sure what has changed recently, possibly the 5.5.2 to 5.5.3 update?)

This can be easily patched by just projecting the duration selector to a number, but it's not very elegant and it make for very confusing looking observable composition.

Observable
  .of('foo')
  .debounce(() => Observable.of('bar').delay(1000).map(() => 0))
  .subscribe();

The debounce operator does not actually use the value of the duration selector, only its asynchrony to manipulate the debounce operator.

The proper typing should be durationSelector: (value: T) => SubscribableOrPromise<any> (or something more appropriate if any is not acceptable).

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