microsoft / microsoft/TypeScript
Declare TypedArray length
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
Suggestion
🔍 Search Terms
typedarray length tuple typed array
✅ 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
A way to declare a fixed length TypedArray similar to Tuples.
📃 Motivating Example
Consider a hypothetical vector library, similar glmatrix:
function addVector2(out: Float32Array, v1: Float32Array, v2: Float32Array) {
out[0] = v1[0] + v2[0]
out[1] = v1[1] + v2[1]
return out
}
There's currently no way to type check that the arguments are indeed Vector2's and not some other Float32Arrays. This is possible with Tuple types though using regular arrays. Since TypedArrays are inherently fixed length even at runtime, it makes sense for there to be some way of declaring length. Even if this is just a minimum length, that would be a huge improvement since that guarantees out of bounds indexing safety.
💻 Use Cases
Many uses of TypedArrays in JS make assumptions about length. But the main one would probably be vectors, matrices, quarternions, etc.
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
Beginne damit, das angeforderte Verhalten von TypedArrays fester Länge mit bestehenden Tupeltypen und den aktuellen TypedArray-Deklarationen von TypeScript zu vergleichen. Lege fest, wie das Vektorbeispiel typgeprüft werden soll, einschließlich der Frage, ob nur Mindestlängen oder exakte Längen unterstützt werden, und füge Tests hinzu, die zeigen, dass inkompatible TypedArray-Längen abgelehnt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100