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 warning when using nullable reference types with OfType operator #1525

Closed
pellet opened this issue Apr 22, 2021 · 1 comment · Fixed by #1617
Closed

Fix warning when using nullable reference types with OfType operator #1525

pellet opened this issue Apr 22, 2021 · 1 comment · Fixed by #1617

Comments

@pellet
Copy link

pellet commented Apr 22, 2021

Bug

Despite our best efforts, bugs can slip into releases or corner cases forgotten about. We will try our best to remedy the situation
and/or provide workarounds. Note that certain (odd) behaviors are by design and as such are not considered bugs.

Which library version?
v5.0

What are the platform(s), environment(s) and related component version(s)?
.net5.0

What is the use case or problem?
I want to use the OfType operator for filtering out nulls like so:

Observable
    .Return<string?>("blah")
    .OfType<string>()
    .SelectMany(this.audioService.PlayAudioPair)
    .Subscribe();

What is the expected outcome?
No warnings

What is the actual outcome?
When compiled has a warning:
warning CS8620: Argument of type 'IObservable<string?>' cannot be used for parameter 'source' of type 'IObservable<object>' in 'IObservable<string> Observable.OfType<string>(IObservable<object> source)' due to differences in the nullability of reference types.

@pellet
Copy link
Author

pellet commented Apr 23, 2021

I've found the operator .WhereNotNull() is working for me without warnings, but it is from ReactiveUI, it would be nice to have the OfType() operator handling nulls too or something similar in RX if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant