Skip to content

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

@pellet

Description

@pellet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions