MCPcopy Index your code
hub / github.com/nodejs/node / getIterationTypesOfIteratorResult

Function getIterationTypesOfIteratorResult

test/fixtures/snapshot/typescript.js:83449–83480  ·  view source on GitHub ↗

* Gets the *yield* and *return* types of an `IteratorResult`-like type. * * If we are unable to determine a *yield* or a *return* type, `noIterationTypes` is * returned to indicate to the caller that it should handle the error. Otherwise, an * `IterationTypes` rec

(type)

Source from the content-addressed store, hash-verified

83447 * `IterationTypes` record is returned.
83448 */
83449 function getIterationTypesOfIteratorResult(type) {
83450 if (isTypeAny(type)) {
83451 return anyIterationTypes;
83452 }
83453 var cachedTypes = getCachedIterationTypes(type, "iterationTypesOfIteratorResult");
83454 if (cachedTypes) {
83455 return cachedTypes;
83456 }
83457 // As an optimization, if the type is an instantiation of one of the global `IteratorYieldResult<T>`
83458 // or `IteratorReturnResult<TReturn>` types, then just grab its type argument.
83459 if (isReferenceToType(type, getGlobalIteratorYieldResultType(/*reportErrors*/ false))) {
83460 var yieldType_1 = getTypeArguments(type)[0];
83461 return setCachedIterationTypes(type, "iterationTypesOfIteratorResult", createIterationTypes(yieldType_1, /*returnType*/ undefined, /*nextType*/ undefined));
83462 }
83463 if (isReferenceToType(type, getGlobalIteratorReturnResultType(/*reportErrors*/ false))) {
83464 var returnType_1 = getTypeArguments(type)[0];
83465 return setCachedIterationTypes(type, "iterationTypesOfIteratorResult", createIterationTypes(/*yieldType*/ undefined, returnType_1, /*nextType*/ undefined));
83466 }
83467 // Choose any constituents that can produce the requested iteration type.
83468 var yieldIteratorResult = filterType(type, isYieldIteratorResult);
83469 var yieldType = yieldIteratorResult !== neverType ? getTypeOfPropertyOfType(yieldIteratorResult, "value") : undefined;
83470 var returnIteratorResult = filterType(type, isReturnIteratorResult);
83471 var returnType = returnIteratorResult !== neverType ? getTypeOfPropertyOfType(returnIteratorResult, "value") : undefined;
83472 if (!yieldType && !returnType) {
83473 return setCachedIterationTypes(type, "iterationTypesOfIteratorResult", noIterationTypes);
83474 }
83475 // From https://tc39.github.io/ecma262/#sec-iteratorresult-interface
83476 // > ... If the iterator does not have a return value, `value` is `undefined`. In that case, the
83477 // > `value` property may be absent from the conforming object if it does not inherit an explicit
83478 // > `value` property.
83479 return setCachedIterationTypes(type, "iterationTypesOfIteratorResult", createIterationTypes(yieldType, returnType || voidType, /*nextType*/ undefined));
83480 }
83481 /**
83482 * Gets the *yield*, *return*, and *next* types of a the `next()`, `return()`, or
83483 * `throw()` method of an `Iterator`-like or `AsyncIterator`-like type.

Callers 1

Calls 10

isTypeAnyFunction · 0.85
getCachedIterationTypesFunction · 0.85
isReferenceToTypeFunction · 0.85
getTypeArgumentsFunction · 0.85
setCachedIterationTypesFunction · 0.85
createIterationTypesFunction · 0.85
filterTypeFunction · 0.85
getTypeOfPropertyOfTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…