* Gets the "promised type" of a promise. * @param type The type of the promise. * @remarks The "promised type" of a type is the type of the "value" parameter of the "onfulfilled" callback.
(type, errorNode)
| 81262 | * @remarks The "promised type" of a type is the type of the "value" parameter of the "onfulfilled" callback. |
| 81263 | */ |
| 81264 | function getPromisedTypeOfPromise(type, errorNode) { |
| 81265 | // |
| 81266 | // { // type |
| 81267 | // then( // thenFunction |
| 81268 | // onfulfilled: ( // onfulfilledParameterType |
| 81269 | // value: T // valueParameterType |
| 81270 | // ) => any |
| 81271 | // ): any; |
| 81272 | // } |
| 81273 | // |
| 81274 | if (isTypeAny(type)) { |
| 81275 | return undefined; |
| 81276 | } |
| 81277 | var typeAsPromise = type; |
| 81278 | if (typeAsPromise.promisedTypeOfPromise) { |
| 81279 | return typeAsPromise.promisedTypeOfPromise; |
| 81280 | } |
| 81281 | if (isReferenceToType(type, getGlobalPromiseType(/*reportErrors*/ false))) { |
| 81282 | return typeAsPromise.promisedTypeOfPromise = getTypeArguments(type)[0]; |
| 81283 | } |
| 81284 | // primitives with a `{ then() }` won't be unwrapped/adopted. |
| 81285 | if (allTypesAssignableToKind(type, 131068 /* TypeFlags.Primitive */ | 131072 /* TypeFlags.Never */)) { |
| 81286 | return undefined; |
| 81287 | } |
| 81288 | var thenFunction = getTypeOfPropertyOfType(type, "then"); // TODO: GH#18217 |
| 81289 | if (isTypeAny(thenFunction)) { |
| 81290 | return undefined; |
| 81291 | } |
| 81292 | var thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, 0 /* SignatureKind.Call */) : ts.emptyArray; |
| 81293 | if (thenSignatures.length === 0) { |
| 81294 | if (errorNode) { |
| 81295 | error(errorNode, ts.Diagnostics.A_promise_must_have_a_then_method); |
| 81296 | } |
| 81297 | return undefined; |
| 81298 | } |
| 81299 | var onfulfilledParameterType = getTypeWithFacts(getUnionType(ts.map(thenSignatures, getTypeOfFirstParameterOfSignature)), 2097152 /* TypeFacts.NEUndefinedOrNull */); |
| 81300 | if (isTypeAny(onfulfilledParameterType)) { |
| 81301 | return undefined; |
| 81302 | } |
| 81303 | var onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, 0 /* SignatureKind.Call */); |
| 81304 | if (onfulfilledParameterSignatures.length === 0) { |
| 81305 | if (errorNode) { |
| 81306 | error(errorNode, ts.Diagnostics.The_first_parameter_of_the_then_method_of_a_promise_must_be_a_callback); |
| 81307 | } |
| 81308 | return undefined; |
| 81309 | } |
| 81310 | return typeAsPromise.promisedTypeOfPromise = getUnionType(ts.map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature), 2 /* UnionReduction.Subtype */); |
| 81311 | } |
| 81312 | /** |
| 81313 | * Gets the "awaited type" of a type. |
| 81314 | * @param type The type to await. |
no test coverage detected
searching dependent graphs…