Exclude mapped types with optionality modifiers and 'as' clauses from constraint logic (#48273)

* Exclude mapped types with optionality modifiers and 'as' clauses

* Add regression tests
This commit is contained in:
Anders Hejlsberg
2022-03-15 17:37:46 -07:00
committed by GitHub
parent 111ca92646
commit 8e5a84a696
5 changed files with 213 additions and 3 deletions

View File

@@ -12219,9 +12219,10 @@ namespace ts {
}
function isMappedTypeGenericIndexedAccess(type: Type) {
return type.flags & TypeFlags.IndexedAccess && getObjectFlags((type as IndexedAccessType).objectType) & ObjectFlags.Mapped &&
!((type as IndexedAccessType).objectType as MappedType).declaration.nameType &&
!isGenericMappedType((type as IndexedAccessType).objectType) && isGenericIndexType((type as IndexedAccessType).indexType);
let objectType;
return !!(type.flags & TypeFlags.IndexedAccess && getObjectFlags(objectType = (type as IndexedAccessType).objectType) & ObjectFlags.Mapped &&
!isGenericMappedType(objectType) && isGenericIndexType((type as IndexedAccessType).indexType) &&
!(objectType as MappedType).declaration.questionToken && !(objectType as MappedType).declaration.nameType);
}
/**