mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 12:19:32 -05:00
Fixed contextual types of optional properties with exactOptionalPropertyTypes (#55177)
This commit is contained in:
committed by
GitHub
parent
ad7881685a
commit
2be814d927
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user