Ask questionsUnsound `await` handling

async function foo<T>(val: T) {
  const v = await val;
  return v;

async function test() {
  const promise = Promise.resolve(1);
  const val = await foo(promise);
  const a = val.then(); // Runtime error


I assume that await and similar promise methods have signature like this:

await<T>(Promise<T> | T) => T;

This is incorrect. If type of T is not known to be a promise (i.e. unknown or generic T), it is assumed NOT to be a promise, while at runtime it could be a promise.


Answer questions vkurchatkin

Sorry, typo. Fixed the example


Related questions

No questions were found.
Github User Rank List