microsoft / microsoft/TypeScript
Suggestion: a built-in TypedArray interface
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
I would have expected a TypedArray interface to exist in
the built-in declaration libraries. Instead, there are independent types for
Int8Array, etc, with no common base type.
interface Int8Array { /* ... */ }
interface Int8ArrayConstructor { /* ... */ }
declare const Int8Array: Int8ArrayConstructor;
interface Uint8Array { /* ... */ }
interface Uint8ArrayConstructor { /* ... */ }
declare const Uint8Array: Uint8ArrayConstructor;
// ...
It seems sensible that there should be a common TypedArray type, both because
- a TypeScript user might want to declare a variable as a
TypedArray, and - it would reduce repetition in the built-in declaration files
interface TypedArray { /* ... */ }
interface Int8Array extends TypedArray { }
interface Int8ArrayConstructor { /* ... */ }
declare const Int8Array: Int8ArrayConstructor;
interface Uint8Array extends TypedArray { }
interface Uint8ArrayConstructor { /* ... */ }
declare const Uint8Array: Uint8ArrayConstructor;
// ...
Is there a good reason why there is no TypedArray type? If not, I can submit a PR.
Use case
Consider the isTypedArray() function from lodash.
Currently, it is declared as follows:
function isTypedArray(value: any): boolean;
This proposal would enable an appropriate type-guard, without declaring
a convoluted union type:
function isTypedArray(value: any): value is TypedArray;
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con le dichiarazioni integrate in src/lib/es5.d.ts, in particolare con la definizione di Int8Array collegata nell’issue, e confronta le altre dichiarazioni di TypedArray. Consulta il riferimento ECMAScript TypedArray e il caso d’uso di lodash isTypedArray; il lavoro è completo quando è disponibile un tipo TypedArray comune e le dichiarazioni di TypedArray possono usarlo senza perdere i loro tipi specifici.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100