| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| return type; | ||
| } | ||
| if (assumeTrue && type.flags & TypeFlags.Unknown && literal.text === "object") { | ||
| // The pattern x && typeof x === 'object', where x is of type unknown, narrows x to type object. |
There was a problem hiding this comment.
Would be nice to note here that you don't need to check both directions because the typeof x === "object" && x is narrowed as two separate steps. I don't think that would be obvious to a casual reader.
Sorry, something went wrong.
| return false; | ||
| } | ||
|
|
||
| function containsTruthyCheck(source: Node, target: Node) { |
There was a problem hiding this comment.
A comment here that this specifically deals the binary operator precedence. would also be useful. The implementation looks good here, but this function is named something much more general than it actually is and that's going to be confusing in the future.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
With this PR, given a variable x of type unknown, the pattern x && typeof x === 'object' narrows x to object. Previously we'd narrow to object | null because a truthiness check applied to unknown is still unknown (and unknown includes null).
Note that this is a targeted fix for a relatively common pattern. In an ideal world we'd be able to accurately represent types that are known to be truthy, but we currently don't have that ability.
Fixes #36870.