You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionfoo(a: string[]|undefined,b: string[]|undefined){a??=b||[];// doesn't worka??=b??[];// doesn't worka||=(b||[]);// doesn't worka||=b||[];// doesn't work// a ??= b!; // works, so it seems to require the BarBar or QuestionQuestion operator on the RHS// a ?? (a = b || []); // works// a || (a = b || []); // works// if (!a) a = b || []; // worksa.includes('foo');// 'a' is possibly 'undefined'}
π Actual behavior
Error Object is possibly 'undefined'. on the last statement.
π Expected behavior
Each of the assignments should remove undefined from the type.
This might be caused by a faulty control flow graph for compound assingments because the same code written as its downlevel equivalent (see commented out lines) works as expected.
Looks like a duplicate of #40494. Tho according to that issue there's a fix available for 4.2.0 already, which is not working on the nightly in the playground.
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground Link: Provided
π» Code
π Actual behavior
Error
Object is possibly 'undefined'.
on the last statement.π Expected behavior
Each of the assignments should remove
undefined
from the type.This might be caused by a faulty control flow graph for compound assingments because the same code written as its downlevel equivalent (see commented out lines) works as expected.
/cc @Kingwl
The text was updated successfully, but these errors were encountered: