Update LKG to enable improved narrowing in 4.4. #44842
Conversation
| factory.inlineExpressions(compact([...pendingExpressions!, node])) : | ||
| factory.inlineExpressions(compact([...pendingExpressions, node])) : |
DanielRosenwasser
Jul 1, 2021
Author
Member
This one is actually unfortunate - pendingExpressions is actually typed as never because we have an earlier assignment of undefined followed by a check for some(...) which is a type predicate on readonly T[]. Since you can't narrow down a readonly T[] from an undefined, it leaves us with never.
The real culprit is #9998, but it is also strange that we just allow a spread of type never.
|
I did notice one opportunity for a new narrowing: accessing a property on a non-null value. When you write if (foo!.bar) {
// ...
}You shouldn't have to repeat the if (foo!.bar) {
foo.bar.baz()
}I think the only downside is that it's sometimes nice to ensure all uses of a variable look similar. |
|
How did you find all the places to remove |
|
At first it was manual just to get a sense of some patterns it would/wouldn't catch, but then yes, I ran |


Fixes #44841.