microsoft / microsoft/TypeScript
FormData methods should take a Generic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript playground and inspect the types of FormData.entries(), keys(), and values() when passed to Object.fromEntries(). Compare the requested generic behavior with the current FormDataEntryValue result and determine whether a sound, non-breaking definition is possible; done means the motivating example receives a useful type without unsafe assertions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100