Skip to content

Improve Error Reporting: Make Nullness Warning 3261 less intimidating - Part 2 #18171

@isaacabraham

Description

@isaacabraham

Linking to #18170.

What

The standard FS3261 warning for e.g.

let y : string | null = null
let x : string = y // FS3261

is as follows:

warning FS3261: Nullness warning: The types 'string' and 'string | null' do not have equivalent 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` is a non-nullable string but the expression on the right-hand-side of the assignment is nullable, which is not permitted. Consider either changing `x` to be a nullable string, or use a pattern match on the right hand side of the assignment to safely handle the null case. 

or something more generic:

warning FS3261: A non-nullable string was expected, but this expression is a nullable string, which is not permitted. Consider either changing the target to be a nullable string, or use a pattern matching to safely handle the null case.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions