Adding boolean type assertion changes type narrowing #60190
Copy link
Copy link
Closed
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
Description
Activity
- changed the title
[-]Adding boolean type assertion changes type narrowing for undefined[/-][+]Adding boolean type assertion changes type narrowing [/+]on Oct 10, 2024 - addedNot a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
on Oct 10, 2024 RyanCavanaugh commented
on Oct 10, 2024 MemberMore actionsThis was an intentional boundary in #44730
Ryan Cavanaugh (@RyanCavanaugh) Thanks for the quick response! Is there a specific reason why this choice was made? I don't see that listed. Regardless we can close the ticket.
RyanCavanaugh commented
on Oct 10, 2024 MemberMore actionsIIRC it's possible to get into a type resolution circularity with this inference in a way that wouldn't really be solvable, so you need some "out" in cases where you're not using it for narrowing purposes
Reacted by Jon AustinGood to know! That makes sense. Thanks again for your help!
- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
🔎 Search Terms
Type Narrowing
Boolean
Undefined
🕗 Version & Regression Information
Version: 5.6.3
Regression: Unknown
⏯ Playground Link
https://www.typescriptlang.org/play/?noUnusedLocals=true&noUnusedParameters=true#code/GYVwdgxgLglg9mABFApgZygeTCgFMOOALkQwCcYwBzRAH0XABMVhKVGBKRAbwChEBiCAgzIAFpRoBeRAEJZBOAG5+gmMFxQJ1Ln0H7EZFFBBkkigHQQxAQzIBBKLgAMHFfoC+qgUZNnEAORMLGyMAbxevKCQsAjI6FAAKgDucPiEJOSSdAxgzKw4nDzeQiJQ4pIkAEaEADYoNkgy8oruahpakrol+r6m5oRWtg5Orm0CXr3G-YHBBezhHkA
💻 Code
🙁 Actual behavior
foois typed asstring | undefinedifthinghas explicit type ofboolean🙂 Expected behavior
fooshould be typed asstringifthinghas type ofbooleanjust like ifthing's type is inferredAdditional information about the issue
No response