microsoft / microsoft/TypeScript

recursive return type for deterministic generators

Abierto
#27,267 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza comprobando cómo TypeScript tipa actualmente las funciones generadoras y los resultados de Generator.next, y después compara ese comportamiento con el ejemplo immutable-generator. Define si los tipos recursivos de estado de yield son viables y qué comportamiento a nivel de tipos contaría como completado; el issue no nombra archivos ni tests.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.