microsoft / microsoft/TypeScript
recursive return type for deterministic generators
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Suggestion
If a generator neither yields inside a loop nor defers to another generator, it's considered deterministic. For any given number of next calls, the compiler could theoretically reduce the generator to the exact type of its next yield. Of course, because generators are mutable, this isn't true. But what if I'm using a library that allows for immutable generators? For every next call, a new generator is returned. Maybe it should be possible to introspect the order of yields in a deterministic generator, and use that to deduce a recursive type structure that represents an immutable generator.
import immutagen from 'immutagen'
const gen = immutagen(function* foo() {
yield 0
yield 1
})
const a = gen()
const b = a.next()
typeof a // => { value: 0, next: () => typeof b }
typeof b // => { value: 1, next: undefined }
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. new expression-level syntax)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia verificando come TypeScript tipizza attualmente le funzioni generatrici e i risultati di Generator.next, quindi confronta questo comportamento con l'esempio immutable-generator. Definisci se i tipi ricorsivi dello stato di yield sono realizzabili e quale comportamento a livello di tipo dovrebbe essere considerato completato; l'issue non nomina file né test.
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
- Da chiarire
- Idoneità per principianti
- 25/100