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

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

Open
Tracked by #1103
isaacabraham opened this issue Dec 20, 2024 · 0 comments · May be fixed by #18172
Open
Tracked by #1103

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

isaacabraham opened this issue Dec 20, 2024 · 0 comments · May be fixed by #18172

Comments

@isaacabraham
Copy link
Contributor

isaacabraham commented Dec 20, 2024

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

Successfully merging a pull request may close this issue.

1 participant