microsoft / microsoft/TypeScript

Preserve ordered yield types when no logic is involved

Aperta
#43,150 8 commenti 8 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

🔍 Search Terms

yield ordered return types

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Make types more definite for each yielded return value in a generator function

See also https://stackoverflow.com/questions/66538431/function-chain-factory-in-typescript-preserving-input-output-types

📃 Motivating Example

Right now, if I do this:

function* work() {
  yield 1;
  yield 'test';
  return [123];
}

Right now this gives:

const g = work();
g.next().value  // string | number | number[]
g.next().value  // string | number | number[]
g.next().value  // string | number | number[]

But since there's no logic/branching/etc, it would be more helpful to me to have:

const g = work();
g.next().value  // number
g.next().value  // string
g.next().value  // number[]

💻 Use Cases

Sometimes I want to use a function generator to represent a series of steps that I want to examine (whether at runtime or during testing, etc) before deciding whether to continue. In other words, I want to break up a function into a series of "pauseable" steps.

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

L’issue non indica file, test o punti di ingresso. Inizia validando gli esempi dei generatori e rivedendo il caso d’uso collegato di Stack Overflow. Il lavoro è completato quando i risultati successivi del generatore espongono i tipi yield e return ordinati senza modificare il comportamento del runtime JavaScript.

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

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.