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
typeX={a: string}|{b: string}// Works in 4.3.5 and 4.4.2functionfunc1<TextendsX>(value: T){if('a'invalue){consta=value.aconsole.log('a',a)}else{constb=value.bconsole.log('b',b)}}// Works in 4.3.5, not in 4.4.2functionfunc2<TextendsX>(value: T){if('a'invalue){const{ a }=value// Property 'a' does not exist on type 'X'.(2339)console.log('a',a)}else{const{ b }=value// Property 'b' does not exist on type 'X'.(2339)console.log('b',b)}}
π Actual behavior
Types are not narrowed when using destructuring assignment and the compiler throws error 2339.
π Expected behavior
Types are narrowed when using destructuring assignment.
Bug Report
π Search Terms
in operator, narrowing, generics, constraints, destructuring
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Types are not narrowed when using destructuring assignment and the compiler throws error 2339.
π Expected behavior
Types are narrowed when using destructuring assignment.