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

defer type doesn't handle void correctly #4804

Closed
mhverbakel opened this issue May 22, 2019 · 3 comments
Closed

defer type doesn't handle void correctly #4804

mhverbakel opened this issue May 22, 2019 · 3 comments
Labels
bug Confirmed bug TS Issues and PRs related purely to TypeScript issues

Comments

@mhverbakel
Copy link

Bug Report

Current Behavior
When using defer with a () => void factory, the return type will be Observable<any>.

Reproduction
https://stackblitz.com/edit/rxjs-gm1wy5

import { defer } from 'rxjs';

const example = defer(() => {});

// Type of example is Observable<any> but should be Observable<never>.

Expected behavior
When using defer with a () => void factory, the return type will be Observable<never>.

Possible Solution
Adding the following to the declaration:

function defer(observableFactory: () => void): Observable<never>;
@cartant
Copy link
Collaborator

cartant commented May 22, 2019

I don't agree with the expected behaviour. defer should return an ObservableInput and void is not an ObservableInput.

@mhverbakel
Copy link
Author

Fine with me, but then | void should be removed from https:/ReactiveX/rxjs/blob/6.5.2/src/internal/observable/defer.ts#L55.

@cartant
Copy link
Collaborator

cartant commented May 22, 2019

Yikes. I didn't even realise that was there. This should definitely have two signatures.

@cartant cartant added bug Confirmed bug TS Issues and PRs related purely to TypeScript issues labels May 22, 2019
cartant added a commit to cartant/rxjs that referenced this issue May 25, 2019
@benlesh benlesh closed this as completed in 362d1d4 Jun 4, 2019
benlesh pushed a commit that referenced this issue Jun 4, 2019
* test(defer): add failing dtslint test

* fix(defer): use overload sig for void factory

Closes #4804
@lock lock bot locked as resolved and limited conversation to collaborators Jul 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

No branches or pull requests

2 participants