You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this is the correct place to bring this up but the Awaited<T> type as-is broke our build after upgrading from typescript 4.4.3 to 4.5.2.
For reference, here is what Awaited<T> looks like:
/** * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. */typeAwaited<T>=Textendsnull|undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` modeTextendsobject&{then(onfulfilled: infer F): any} ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrappedFextends((value: infer V)=>any) ? // if the argument to `then` is callable, extracts the argumentAwaited<V> : // recursively unwrap the valuenever : // the argument to `then` was not callableT;// non-object or non-thenable
The problem is that we have a custom Promise class (AbortablePromise) and its then function accepts a onfulfilled callback that do not exactly match the condition F extends ((value: infer V) => any).
So onfulfilled in our case is (value: T, abortController: AbortController) => TResult1 | PromiseLike<TResult1>) which does not match (value: infer V) => any
Hence, Awaited<T> where T is an AbortablePromise always returns never.
Would it be possible to make the type condition more flexible in Awaited<T> to enable these promise extensions and still have the type be compatible with Promise.all, Promise.race, etc?
Hello everyone,
Not sure if this is the correct place to bring this up but the
Awaited<T>
type as-is broke our build after upgrading from typescript 4.4.3 to 4.5.2.For reference, here is what
Awaited<T>
looks like:The problem is that we have a custom Promise class (
AbortablePromise
) and itsthen
function accepts aonfulfilled
callback that do not exactly match the conditionF extends ((value: infer V) => any)
.Our
then
is declared like this:So
onfulfilled
in our case is(value: T, abortController: AbortController) => TResult1 | PromiseLike<TResult1>)
which does not match(value: infer V) => any
Hence,
Awaited<T>
whereT
is anAbortablePromise
always returnsnever
.Would it be possible to make the type condition more flexible in
Awaited<T>
to enable these promise extensions and still have the type be compatible withPromise.all
,Promise.race
, etc?Originally posted by @julienavert in #45350 (comment)
The text was updated successfully, but these errors were encountered: