mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Handle nullable discriminants in non-strictNullChecks mode
This commit is contained in:
1 parent
9323ec0786
commit
f1c7c9fdc7
1 file changed
+5
-1
@@ -24177,7 +24177,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
if (include[i]) {
|
||||
const targetType = getTypeOfPropertyOrIndexSignatureOfType(types[i], propertyName);
|
||||
if (targetType && !isIntersectionEmpty(getDiscriminatingType(), targetType)) {
|
||||
if (targetType && isMatchingDiscriminantType(getDiscriminatingType(), targetType)) {
|
||||
matched = true;
|
||||
}
|
||||
else {
|
||||
@@ -24196,6 +24196,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return filtered.flags & TypeFlags.Never ? target : filtered;
|
||||
}
|
||||
|
||||
function isMatchingDiscriminantType(source: Type, target: Type) {
|
||||
return !strictNullChecks && !!(source.flags & TypeFlags.Nullable) || !isIntersectionEmpty(source, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* A type is 'weak' if it is an object type with at least one optional property
|
||||
* and no required properties, call/construct signatures or index signatures
|
||||
|
||||
Reference in new issue
Block a user