microsoft / microsoft/TypeScript
Tuple iteration and merging
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Edit: Remove indexing part
Edit 2: Replace tuple mapping syntax with normal mapped types
Search Terms
Concatentate and merge tuples' entries.
Suggestion
- I would like to be able to extract and spread in positions other than the last part of a tuple.
- I would like to merge a tuple into an intersection or concatenation of its members.
Use Cases
- Converting a tuple to its intersection, such as with
Object.assign's assignee. - Typing
Array.prototype.concatcorrectly for tuples.
Syntax
The syntax comes in a few new forms:
[...A, B]appendsBto the tupleA. Similarly,[...infer A, any] extends B ? A : []drops the last item of the tuple and[...any[], infer A] extends B ? A : neverextracts the first.{... ...T}for an n-ary merge and[... ...T]an n-ary concatenation.
Examples
Here's the types for each method I mentioned above.
interface Array<T> {
concat<U extends any[]>(...others: U): [...this, ... ...{[I in keyof U]: (
U[I] extends any[] ? N : U[I] extends ArrayLike<infer R> ? R[] : [U[I]]
)}];
}
interface ObjectConstructor {
assign(target: {... ...typeof sources}, ...sources: object[]): typeof target;
}
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)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue schlägt Tuple-Spreading, Tuple-Konkatenation und das Zusammenführen von Tupeln zu Intersections im Typsystem von TypeScript vor, mit Beispielen für Array.concat und Object.assign. Es sind keine Implementierungsdateien, Tests oder Einstiegspunkte genannt; ermittle zuerst den relevanten Bereich des Typsystems und erstelle dann Tests, die zeigen, dass das vorgeschlagene Tupelverhalten und die Beispiele funktionieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100