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
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.
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.
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.
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)
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. :-)
Most helpful comment
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