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
Sorry if this has been reported before, I tried my best searching for similar issues. I guess this is more of a "Is this 'As Designed'?" question as opposed to a bug report. It's caught me off guard a few times and thought I'd mention it at least.
TypeScript Version: 3.1.1
Search Terms: Type check, null, undefined
Code
// Example 1constmyNumber=32;if(myNumber===undefined){console.log('This will never run');}// Example 2consttest: number|null=null;if(test===undefined){console.log('Woof');}else{console.log('Meow');}
Expected behavior:
A warning on line 2 in both examples that myNumber/test will never be undefined. (Or line 3 that the code is unreachable).
Actual behavior:
Code compiles fine without issue.
functionisUndefined<Textends(undefinedextendsT ? any : never)>(value: T): value is T&undefined{returnvalue===undefined;}// Example 1constmyNumber=32;if(isUndefined(myNumber)){// ^^^^^^^^ Error: argument of type number is not assignable to type never console.log('This will never run');}
The error is not in unreachable code, but a useless comparison.
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
Sorry if this has been reported before, I tried my best searching for similar issues. I guess this is more of a "Is this 'As Designed'?" question as opposed to a bug report. It's caught me off guard a few times and thought I'd mention it at least.
TypeScript Version: 3.1.1
Search Terms: Type check, null, undefined
Code
Expected behavior:
A warning on line 2 in both examples that
myNumber
/test
will never be undefined. (Or line 3 that the code is unreachable).Actual behavior:
Code compiles fine without issue.
Playground Link: http://www.typescriptlang.org/play/#src=%2F%2F%20Example%201%0D%0Aconst%20myNumber%20%3A%20number%20%3D%2032%3B%0D%0Aif%20(myNumber%20%3D%3D%3D%20undefined)%20%7B%0D%0A%20%20console.log('This%20will%20never%20run')%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20Example%202%0D%0Aconst%20test%20%3A%20number%20%7C%20null%20%3D%20null%3B%0D%0Aif%20(test%20%3D%3D%3D%20undefined)%20%7B%0D%0A%20%20console.log('Woof')%3B%0D%0A%7D%20else%20%7B%0D%0A%20%20console.log('Meow')%3B%0D%0A%7D
Related Issues: No
The text was updated successfully, but these errors were encountered: