<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨 --> <!-- Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please help us by doing the following steps before logging an issue: * Search: https://github.com/Microsoft/TypeScript/search?type=Issues * Read the CONTRIBUTING guidelines: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ --> <!-- If you have a QUESTION: THIS IS NOT A FORUM FOR QUESTIONS. Ask questions at http://stackoverflow.com/questions/tagged/typescript or https://gitter.im/Microsoft/TypeScript --> <!-- If you have a SUGGESTION: Most suggestion reports are duplicates, please search extra hard before logging a new suggestion. See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --> <!-- If you have a BUG: Please fill in the *entire* template below. --> <!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. --> **TypeScript Version:** 2.7.0-dev.201xxxxx <!-- Search terms you tried before logging this (so others can find this issue more easily) --> **Search Terms:** multi variable control flow analysis typescript **Code** ```ts declare const cleft: number | undefined; declare const cright: number | undefined; if (typeof cleft === 'number') { cleft.toExponential(); } else { cleft.toExpontential(); // Error } if (typeof cleft === 'undefined' && typeof cright === 'undefined') { cleft.toExponential(); // Error } else if (typeof cleft === 'undefined' && typeof cright !== 'undefined') { cleft.toExponential(); // Error } else if (typeof cleft !== 'undefined' && typeof cright === 'undefined') { cleft.toExponential(); } else { cleft.toExponential(); // Error But shouldn't } ``` **Expected behavior:** No error on the last else body. **Actual behavior:** Error on the last else body. **Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior --> http://www.typescriptlang.org/play/#src=%0Adeclare%20const%20cleft%3A%20number%20%7C%20undefined%3B%0Adeclare%20const%20cright%3A%20number%20%7C%20undefined%3B%0A%0Aif%20(typeof%20cleft%20%3D%3D%3D%20'number')%20%7B%0A%20%20%20%20cleft.toExponential()%3B%0A%7D%0Aelse%20%7B%0A%20%20%20%20cleft.toExpontential()%3B%20%2F%2F%20Error%0A%7D%0A%0Aif%20(typeof%20cleft%20%3D%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20%3D%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%20%20%20%20%0A%7D%0Aelse%20if%20(typeof%20cleft%20%3D%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20!%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%7D%0Aelse%20if%20(typeof%20cleft%20!%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20%3D%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%0A%7D%0Aelse%20%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%7D%0A **Related Issues:**
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
multi variable control flow analysis typescript
Code
Expected behavior:
No error on the last else body.
Actual behavior:
Error on the last else body.
Playground Link:
http://www.typescriptlang.org/play/#src=%0Adeclare%20const%20cleft%3A%20number%20%7C%20undefined%3B%0Adeclare%20const%20cright%3A%20number%20%7C%20undefined%3B%0A%0Aif%20(typeof%20cleft%20%3D%3D%3D%20'number')%20%7B%0A%20%20%20%20cleft.toExponential()%3B%0A%7D%0Aelse%20%7B%0A%20%20%20%20cleft.toExpontential()%3B%20%2F%2F%20Error%0A%7D%0A%0Aif%20(typeof%20cleft%20%3D%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20%3D%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%20%20%20%20%0A%7D%0Aelse%20if%20(typeof%20cleft%20%3D%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20!%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%7D%0Aelse%20if%20(typeof%20cleft%20!%3D%3D%20'undefined'%20%26%26%0A%20%20%20%20typeof%20cright%20%3D%3D%3D%20'undefined')%0A%7B%0A%20%20%20%20cleft.toExponential()%3B%0A%7D%0Aelse%20%7B%0A%20%20%20%20cleft.toExponential()%3B%20%2F%2F%20Error%0A%7D%0A
Related Issues: