microsoft / microsoft/TypeScript
FormData methods should take a Generic
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Suggestion
🔍 Search Terms
Form Data, .entries()
✅ 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
FormData entries() method, and perhaps .keys() and .values() should take a generic.
Right now it returns FormDataEntry value and is difficult type type the returned value of that Iterable.
📃 Motivating Example
Example of the problem here:
Feeding the .entries() Iterable into Object.fromEntries(), gives us a type of { [k: string]: FormDataEntryValue; }, and has no overlap between the acutal data (Person in my case) that is supposed to come back.
So perhaps something like formData.entries<Person>() or formData.entries<IterableIterator<Person>>()?
I just know it's really hard to convert the result into a type. And the solutions are either as unknown as Person or a Type Guard, which makes me manually type each property.
💻 Use Cases
See above link example
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el playground de TypeScript enlazado e inspecciona los tipos de FormData.entries(), keys() y values() al pasarlos a Object.fromEntries(). Compara el comportamiento genérico solicitado con el resultado actual de FormDataEntryValue y determina si es posible una definición sólida que no introduzca cambios incompatibles; se considera terminado cuando el ejemplo motivador recibe un tipo útil sin assertions inseguras.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100