Fix NarrowTypeByTypeof, NarrowTypeByInstanceof, isPropertyInitializedInConstructor
This commit is contained in:
parent
0a041ee536
commit
343e0f7fd9
1 changed files with 7 additions and 12 deletions
|
@ -15045,11 +15045,6 @@ namespace ts {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNarrowableDeclaredType(expr: Node) {
|
|
||||||
const type = getDeclaredTypeOfReference(expr);
|
|
||||||
return !!(type && type.flags & TypeFlags.Union);
|
|
||||||
}
|
|
||||||
|
|
||||||
function findDiscriminantProperties(sourceProperties: Symbol[], target: Type): Symbol[] | undefined {
|
function findDiscriminantProperties(sourceProperties: Symbol[], target: Type): Symbol[] | undefined {
|
||||||
let result: Symbol[] | undefined;
|
let result: Symbol[] | undefined;
|
||||||
for (const sourceProperty of sourceProperties) {
|
for (const sourceProperty of sourceProperties) {
|
||||||
|
@ -16107,9 +16102,9 @@ namespace ts {
|
||||||
// We have '==', '!=', '====', or !==' operator with 'typeof xxx' and string literal operands
|
// We have '==', '!=', '====', or !==' operator with 'typeof xxx' and string literal operands
|
||||||
const target = getReferenceCandidate(typeOfExpr.expression);
|
const target = getReferenceCandidate(typeOfExpr.expression);
|
||||||
if (!isMatchingReference(reference, target)) {
|
if (!isMatchingReference(reference, target)) {
|
||||||
// For a reference of the form 'x.y', where 'x' has a narrowable declared type, a
|
// For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the
|
||||||
// 'typeof x === ...' type guard resets the narrowed type of 'y' to its declared type.
|
// narrowed type of 'y' to its declared type.
|
||||||
if (containsMatchingReference(reference, target) && hasNarrowableDeclaredType(target)) {
|
if (containsMatchingReference(reference, target)) {
|
||||||
return declaredType;
|
return declaredType;
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
|
@ -16264,9 +16259,9 @@ namespace ts {
|
||||||
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
|
function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
|
||||||
const left = getReferenceCandidate(expr.left);
|
const left = getReferenceCandidate(expr.left);
|
||||||
if (!isMatchingReference(reference, left)) {
|
if (!isMatchingReference(reference, left)) {
|
||||||
// For a reference of the form 'x.y', where 'x' has a narrowable declared type, an
|
// For a reference of the form 'x.y', an 'x instanceof T' type guard resets the
|
||||||
// 'x instanceof T' type guard resets the narrowed type of 'y' to its declared type.
|
// narrowed type of 'y' to its declared type.
|
||||||
if (containsMatchingReference(reference, left) && hasNarrowableDeclaredType(left)) {
|
if (containsMatchingReference(reference, left)) {
|
||||||
return declaredType;
|
return declaredType;
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
|
@ -27221,7 +27216,7 @@ namespace ts {
|
||||||
reference.expression.parent = reference;
|
reference.expression.parent = reference;
|
||||||
reference.parent = constructor;
|
reference.parent = constructor;
|
||||||
reference.flowNode = constructor.returnFlowNode;
|
reference.flowNode = constructor.returnFlowNode;
|
||||||
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
|
const flowType = getFlowTypeOfReference(reference, getOptionalType(propType));
|
||||||
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
|
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue