Skip to content

Improve Error Reporting: Make Nullness Warning 3261 less intimidating #18170

@isaacabraham

Description

@isaacabraham

What

The standard FS3261 warning for e.g.

let x : string | null = null
x.Length // unsafe access - FS3261

is as follows:

warning FS3261: Nullness warning: The types 'string' and 'string | null' do not have compatible nullability.

Why

This error is not especially friendly or easy to understand, nor does it give a solution to fix the issue.

How

Consider replacing with:

warning FS3261: The symbol `x` may be null, and accessing the `Length` member could lead to a runtime exception. Consider pattern matching and / or converting to an Option using 'Option.ofObj' to safely access the value.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions