@@ -19927,10 +19927,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1992719927 let reportedError = false;
1992819928 for (const value of iterator) {
1992919929 const { errorNode: prop, innerExpression: next, nameType, errorMessage } = value;
19930- const targetPropType = getBestMatchIndexedAccessTypeOrUndefined(source, target, nameType);
19930+ let targetPropType = getBestMatchIndexedAccessTypeOrUndefined(source, target, nameType);
1993119931 if (!targetPropType || targetPropType.flags & TypeFlags.IndexedAccess) continue; // Don't elaborate on indexes on generic variables
19932- const sourcePropType = getIndexedAccessTypeOrUndefined(source, nameType);
19932+ let sourcePropType = getIndexedAccessTypeOrUndefined(source, nameType);
1993319933 if (!sourcePropType) continue;
19934+ const propName = getPropertyNameFromIndex(nameType, /*accessNode*/ undefined);
1993419935 if (!checkTypeRelatedTo(sourcePropType, targetPropType, relation, /*errorNode*/ undefined)) {
1993519936 const elaborated = next && elaborateError(next, sourcePropType, targetPropType, relation, /*headMessage*/ undefined, containingMessageChain, errorOutputContainer);
1993619937 reportedError = true;
@@ -19945,6 +19946,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1994519946 resultObj.errors = [diag];
1994619947 }
1994719948 else {
19949+ const targetIsOptional = !!(propName && (getPropertyOfType(target, propName) || unknownSymbol).flags & SymbolFlags.Optional);
19950+ const sourceIsOptional = !!(propName && (getPropertyOfType(source, propName) || unknownSymbol).flags & SymbolFlags.Optional);
19951+ targetPropType = removeMissingType(targetPropType, targetIsOptional);
19952+ sourcePropType = removeMissingType(sourcePropType, targetIsOptional && sourceIsOptional);
1994819953 const result = checkTypeRelatedTo(specificSource, targetPropType, relation, prop, errorMessage, containingMessageChain, resultObj);
1994919954 if (result && specificSource !== sourcePropType) {
1995019955 // If for whatever reason the expression type doesn't yield an error, make sure we still issue an error on the sourcePropType
0 commit comments