diff --git a/spec-dtslint/observables/from-spec.ts b/spec-dtslint/observables/from-spec.ts new file mode 100644 index 0000000000..ec0cb7fb62 --- /dev/null +++ b/spec-dtslint/observables/from-spec.ts @@ -0,0 +1,45 @@ +import { from, of, asyncScheduler } from 'rxjs'; + +it('should accept an array', () => { + const o = from([1, 2, 3, 4]); // $ExpectType Observable +}); + +it('should accept a Promise', () => { + const o = from(Promise.resolve('test')); // $ExpectType Observable +}); + +it('should accept an Iterable', () => { + const iterable = (function*() { + yield 42; + }()); + + const o = from(iterable); // $ExpectType Observable +}); + +it('should accept an Observable', () => { + const o = from(of('test')); // $ExpectType Observable +}); + +it('should accept union types', () => { + const o = from(Math.random() > 0.5 ? of(123) : of('test')); // $ExpectType Observable +}); + +it('should accept Observable>', () => { + const o = from(of(of(123))); // $ExpectType Observable> +}); + +it('should accept Observable', () => { + const o = from(of([1, 2, 3])); // $ExpectType Observable +}); + +it('should accept an array of Observables', () => { + const o = from([of(1), of(2), of(3)]); // $ExpectType Observable> +}); + +it('should accept an array of Inputs', () => { + const iterable = (function*() { + yield 42; + }()); + + const o = from([of(1), ['test'], iterable]); // $ExpectType Observable | IterableIterator | string[]> +}); diff --git a/src/internal/observable/from.ts b/src/internal/observable/from.ts index cb3a5437c7..2a4f56d64f 100644 --- a/src/internal/observable/from.ts +++ b/src/internal/observable/from.ts @@ -8,10 +8,9 @@ import { fromPromise } from './fromPromise'; import { fromIterable } from './fromIterable'; import { fromObservable } from './fromObservable'; import { subscribeTo } from '../util/subscribeTo'; -import { ObservableInput, SchedulerLike } from '../types'; +import { ObservableInput, SchedulerLike, ObservedValueOf } from '../types'; -export function from(input: ObservableInput, scheduler?: SchedulerLike): Observable; -export function from(input: ObservableInput>, scheduler?: SchedulerLike): Observable>; +export function from>(input: O, scheduler?: SchedulerLike): Observable>; /** * Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.