If expression only considers the type it returns when true rather than the type the expression applies to

Reproduction Steps

local x: string? = if condition then "" else nil

Expected Behavior
if expression should consider the type of what it is being assigned to or used in

Actual Behavior
It will always warn if the false value doesn’t fit within the true value’s type.
example

Workaround
Cast true value to a type that fits both

local x: string? = if condition then "" :: string? else nil

or use the old and…or if the true value isn’t falsy, which will give a union of both types
example

Issue Area: Studio
Issue Type: Other
Impact: Low
Frequency: Constantly

2 Likes

Thank you for the report. A fix for this will be released soon.

2 Likes

A fix for this false-positive error has been released.

4 Likes