-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type guards are not working properly in Observable #19334
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
Comments
I think this could be done by updating the rxjs types. If // from lib.es5.d.ts
filter<S extends T>(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; What version of |
@Andy-MS I'm using import { Observable } from '../Observable';
export declare function filter<T, S extends T>(this: Observable<T>, predicate: (value: T, index: number) => value is S, thisArg?: any): Observable<S>;
export declare function filter<T>(this: Observable<T>, predicate: (value: T, index: number) => boolean, thisArg?: any): Observable<T>; |
I found this issue. Is this a duplication? |
Even with
And even if I change that line to |
@Andy-MS you're missing the |
I updated my question :) |
OK, now the example will work if you replace |
@Andy-MS that's interesting! Thanks a lot. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.5.3
Code
A simple example to reproduce.
Expected behavior:
Type guards must make sure the flow continues according to the current status of types.
Actual behavior:
Apparently because the type guard is not within a branch it is not working as intended, or it is working as intended by design that I personally think is not a good idea.
The text was updated successfully, but these errors were encountered: