Fixed contextual types of optional properties with exactOptionalPropertyTypes (#55177)

This commit is contained in:
Mateusz Burzyński
2023-08-08 23:42:50 +02:00
committed by GitHub
parent ad7881685a
commit 2be814d927
7 changed files with 196 additions and 2 deletions

View File

@@ -29247,7 +29247,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else if (t.flags & TypeFlags.StructuredType) {
const prop = getPropertyOfType(t, name);
if (prop) {
return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop);
return isCircularMappedProperty(prop) ? undefined : removeMissingType(getTypeOfSymbol(prop), !!(prop && prop.flags & SymbolFlags.Optional));
}
if (isTupleType(t) && isNumericLiteralName(name) && +name >= 0) {
const restType = getElementTypeOfSliceOfTupleType(t, t.target.fixedLength, /*endSkipCount*/ 0, /*writing*/ false, /*noReductions*/ true);
@@ -29324,7 +29324,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// If index is before any spread element and within the fixed part of the contextual tuple type, return
// the type of the contextual tuple element.
if ((firstSpreadIndex === undefined || index < firstSpreadIndex) && index < t.target.fixedLength) {
return getTypeArguments(t)[index];
return removeMissingType(getTypeArguments(t)[index], !!(t.target.elementFlags[index] && ElementFlags.Optional));
}
// When the length is known and the index is after all spread elements we compute the offset from the element
// to the end and the number of ending fixed elements in the contextual tuple type.