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

[Bug] Typings startWith #5382

Closed
niklas-wortmann opened this issue Apr 7, 2020 · 6 comments
Closed

[Bug] Typings startWith #5382

niklas-wortmann opened this issue Apr 7, 2020 · 6 comments
Labels
bug Confirmed bug

Comments

@niklas-wortmann
Copy link
Member

It seems like there is a bug in the typing for startWith.
It seems like it is introduced with #5376

TS throws following error:

Type `...` is missing the following properties from type `SchedulerLike`...

This occurs when ts is falling back to the following type signature of startWith:

export function startWith<T>(scheduler: SchedulerLike): MonoTypeOperatorFunction<T>;

This could occur for example by doing the following:

of(true).pipe(
    startWith<boolean>(undefined)
);

In general, this problem occurred recently in G3 so it is at least some kind of breaking behavior

@niklas-wortmann niklas-wortmann changed the title Typings startWith [Bug] Typings startWith Apr 7, 2020
@niklas-wortmann niklas-wortmann added AGENDA ITEM Flagged for discussion at core team meetings bug Confirmed bug labels Apr 7, 2020
@cartant
Copy link
Collaborator

cartant commented Apr 7, 2020

Not a bug, IMO.

Without the explicit type argument, it should effect the correct type:

of(true).pipe(startWith(undefined)); // Observable<boolean | undefined>

If the explicit type parameter is specified, there is no way this can be satisfied, as undefined is assignable to neither boolean nor SchedulerLike.

@niklas-wortmann
Copy link
Member Author

It also doesn't work if you set the explicit type parameter to boolean. And for some reason this was just popping up at google, so I don't know, but it seems like a regression or something.

@cartant
Copy link
Collaborator

cartant commented Apr 7, 2020

The answer is to not use an explicit type parameter - this is Google's own advice. Or, if one is to be specified, specify one that's compatible with the argument being passed:

of(true).pipe(startWith<boolean | undefined>(undefined));

Not a bug, IMO.

@leggechr
Copy link
Contributor

leggechr commented Apr 8, 2020

Even of(true).pipe(startWith<boolean | undefined>(undefined)); is not working. It gives the same error Jan-Niklas mentioned above. The only way I could get it to work is with

startWith(undefined as boolean|undefined)

@benlesh benlesh removed the AGENDA ITEM Flagged for discussion at core team meetings label Apr 8, 2020
@Airblader
Copy link
Contributor

Airblader commented Oct 7, 2020

This is particularly annoying on void observables, such as Subject<void>. I really just want startWith() which typechecks but doesn't work, and because of this issue startWith(undefined) works but shows as a deprecated signature. The only way to truly have it work is then something like startWith(undefined as void) which is slightly insane. :-)

@cartant
Copy link
Collaborator

cartant commented Mar 13, 2021

Addressed in #6114

@cartant cartant closed this as completed Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants