Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

Missing definition to support generators in Typescript #1243

Open Jason-Rev opened 8 years ago

Jason-Rev commented 8 years ago

RxJS 4.1 generator support in Typescript

There is a nice example on how to use generators with RxJS here: Generators and Observable Sequences

Problem

When trying to use the example fibonacci code in Typescript, you get a compile error:

error TS2345: Argument of type 'IterableIterator<number>' is not assignable to parameter of type 'number[] | { [index: number]: number; length: number; }'.
  Type 'IterableIterator<number>' is not assignable to type '{ [index: number]: number; length: number; }'.
    Property 'length' is missing in type 'IterableIterator<number>'.

Missing Definitions

It seems the support for Iterable and IterableIterator are missing from ObservableStatic

Workaround

Current workaround is to add the following to global.d.ts so that the compiler stops complaining.

declare module Rx {
    export interface ObservableStatic {
        /**
         * This method creates a new Observable sequence from an array-like or iterable object.
         * @param {Any} arrayLike An array-like or iterable object to convert to an Observable sequence.
         * @param {Function} [mapFn] Map function to call on every element of the array.
         * @param {Any} [thisArg] The context to use calling the mapFn if provided.
         * @param {Scheduler} [scheduler] Optional scheduler to use for scheduling.  If not provided, defaults to Scheduler.currentThread.
         */
        from<T>(iterator: Iterable<T>): Rx.Observable<T>;
        from<T>(iterator: IterableIterator<T>): Rx.Observable<T>;
    }
}
schaze commented 6 years ago

Why is this open for already 2 years? Isn't the solution already posted in here as well?