Async function with a typed result rejects a returned checked-dynamic promise

Aperta
#3,078 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@alantriesagain ci sta già lavorando.

Dal 6/11/2026.

  • #3083 di @alantriesagain — aperta
  • #3104 di @ctate — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
compilers

Direzione di ricerca

The report provides a JavaScript reproduction and says the failure also occurs on main at commit 979a65246, but names no implementation files or tests. Start by tracing how typed async function returns and concise async arrow bodies handle checked-dynamic values, then find the related compiler tests. Done means both forms adopt returned promises with the stated turn order and settle other values without an extra turn.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Async function with a typed result rejects a returned checked-dynamic promise

An async function whose result is typed checks a returned checked-dynamic value against that type directly. When the value is a promise, JavaScript resolves the function's promise with that promise: the promise is adopted, not converted as a plain value.

In our model layer, uploadFiles takes a schema whose type does not map, so its call is checked-dynamic. return uploadFiles(...) from a typed async function failed at run time with expected object at $, got Promise. Node resolves the returned promise.

/** @returns {Promise<{ id: string }>} */
async function load() {
  const opaque = (value) => value;
  return opaque(Promise.resolve({ id: "a" }));
}

load().then((value) => console.log(value.id));

On 0.4.8, the compiled program throws Uncaught TypeError: expected object at $, got Promise; Node prints a. The same failure reproduces on main (979a65246).

The same rule should apply to concise async arrow bodies. A promise behind the dynamic value should be adopted with the turn order of a returned typed promise: the then job's turn, then its settlement, after every crossed finally and outside the function's own catch. Any other value should settle the function at once, with no extra turn.

I opened #TBD with a patch for both forms.

Lingua principale
TypeScript
Stelle
6.4k
Fork
204
Merge medio
9h 48m
PR unite (30g)
795

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.