mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 10:55:15 -06:00
Suport both x != null and x != undefined in non-null type guards
This commit is contained in:
parent
d10017f165
commit
ed40fbf2d8
@ -6986,6 +6986,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isNullOrUndefinedLiteral(node: Expression) {
|
||||
return node.kind === SyntaxKind.NullKeyword ||
|
||||
node.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>node) === undefinedSymbol;
|
||||
}
|
||||
|
||||
// Get the narrowed type of a given symbol at a given location
|
||||
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {
|
||||
let type = getTypeOfSymbol(symbol);
|
||||
@ -7069,7 +7074,7 @@ namespace ts {
|
||||
switch (expr.operatorToken.kind) {
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
if (expr.right.kind === SyntaxKind.NullKeyword) {
|
||||
if (isNullOrUndefinedLiteral(expr.right)) {
|
||||
return narrowTypeByNullCheck(type, expr, assumeTrue);
|
||||
}
|
||||
// Fall through
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user