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>;
}
}
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:
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.