Fixed an issue with self-referential awaited union (#49677)

This commit is contained in:
Mateusz Burzyński
2022-06-29 22:01:36 +02:00
committed by GitHub
parent 52f4055174
commit bd11ce2aeb
5 changed files with 134 additions and 1 deletions

View File

@@ -36625,8 +36625,20 @@ namespace ts {
// For a union, get a union of the awaited types of each constituent.
if (type.flags & TypeFlags.Union) {
if (awaitedTypeStack.lastIndexOf(type.id) >= 0) {
if (errorNode) {
error(errorNode, Diagnostics.Type_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method);
}
return undefined;
}
const mapper = errorNode ? (constituentType: Type) => getAwaitedTypeNoAlias(constituentType, errorNode, diagnosticMessage, arg0) : getAwaitedTypeNoAlias;
return typeAsAwaitable.awaitedTypeOfType = mapType(type, mapper);
awaitedTypeStack.push(type.id);
const mapped = mapType(type, mapper);
awaitedTypeStack.pop();
return typeAsAwaitable.awaitedTypeOfType = mapped;
}
const thisTypeForErrorOut: { value: Type | undefined } = { value: undefined };