Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(defer): restrict allowed factory types #4835

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(defer): restrict allowed factory types
  • Loading branch information
cartant committed Jun 5, 2019
commit 024c772485cfcc45953ff125bc2992c192b75e6f
10 changes: 4 additions & 6 deletions src/internal/observable/defer.ts
Original file line number Diff line number Diff line change
@@ -52,18 +52,16 @@ import { empty } from './empty';
* @name defer
* @owner Observable
*/
export function defer<O extends ObservableInput<any>>(observableFactory: () => O): Observable<ObservedValueOf<O>>;
export function defer(observableFactory: () => void): Observable<never>;
export function defer<O extends ObservableInput<any>>(observableFactory: () => O | void): Observable<ObservedValueOf<O>> {
return new Observable<ObservedValueOf<O>>(subscriber => {
let input: O | void;
export function defer<R extends ObservableInput<any> | void>(observableFactory: () => R): Observable<ObservedValueOf<R>> {
return new Observable<ObservedValueOf<R>>(subscriber => {
let input: R | void;
try {
input = observableFactory();
} catch (err) {
subscriber.error(err);
return undefined;
}
const source = input ? from(input) : empty();
const source = input ? from(input as ObservableInput<ObservedValueOf<R>>) : empty();
return source.subscribe(subscriber);
});
}