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
letgreeting: null|string=null;/* A error */functionsetIt(){greeting="Hello!"};setIt()/* B error */setTimeout(()=>greeting="Hello!",0);/* C error */construnCallback=(cb: ()=>void)=>cb();runCallback(()=>greeting="Hello!");/* D ok */// ((() => { greeting = "Hello!" })())/* E ok */// greeting = Math.random() > 0.5 ? "Hello!" : null;if(greeting){greeting.toUpperCase();// Property 'toUpperCase' does not exist on type 'never'.}if(greeting!=null&&greeting!==null){greeting.toUpperCase();// Property 'toUpperCase' does not exist on type 'never'.}if(typeofgreeting==="string"){greeting.toUpperCase();// Property 'toUpperCase' does not exist on type 'never'.}
Expected behavior: greeting should have type string Inside all if-blocks - not never. This should be true for
all (activated exclusively) test cases (A to E).
Actual behavior: greeting has type never inside the if-blocks (for test cases A, B and C). It appears that the assignments to greeting are not recognized. For test cases D and E everything is working as expected.
TypeScript Version: up to latest version
3.8-Beta
Search Terms:
Code
Expected behavior:
greeting
should have typestring
Inside all if-blocks - notnever
. This should be true forall (activated exclusively) test cases (A to E).
Actual behavior:
greeting
has typenever
inside the if-blocks (for test cases A, B and C). It appears that the assignments togreeting
are not recognized. For test cases D and E everything is working as expected.Playground Link: https://www.typescriptlang.org/play/?ts=3.8-Beta&ssl=1&ssc=1&pln=17&pc=2#code/DYUwLgBA5gTi4EsB2UBcEkFdjAgHwgGcwZkoIBeDbYAbgFgAoJgegCoIBBCEGGAexgQ2LCGIgAzTEgDGYBPyRFwASTAAKAJQQA3tDiIUlCACIAEiBz8AhCYgBfWsrBqtrDgCEefQcNHjCcAAVBABbEH5MDS1KAD59eHkjKnNLYBsTABoIAAZNBkZ2CABhbwEhEXEIGUViCBhpYoBDHAAjJpkAa2N1GVb0GIp4gDd+BAATbSHq1q0nBqRmto7O9UH42ESyY1SrW3z3CAARCH5u8UqWUTX13QTDchSLPbt7TS1NQ4BRU-OxS9EmwexgAsk0wAALAB0MCaSHG-FCMXiOShAFYIAB+UzPdK2CDoLA4ApMBASCDqIFJKDaHRMKpUshQsD8ACqAAd2bxmoE5hArhAAAoCLkwMAATwgAHIWRzRTyQFKIAiQIQMPxICAAB4IOqKCASrnSpAgYa8KVQpj2UnkykGakQaxUIm4ABkrvuDqdzpotPp4kZKGZbM53KavPy-NEwv4ool0tloZgCqVKrVSA1PB1eqUhpAxtN5stjGtjDJFLz-HJgceFBSxFIKBMfsYDPtTMT8vDID5ApjcclMpDXcCqf4qvVmuzkH1eYLZpgFqtQA
Related Issues: Maybe to #36777
The text was updated successfully, but these errors were encountered: