microsoft / microsoft/TypeScript
Add overload to `unshift` to catch calling it with zero elements
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
lib Update Request
I often mistake unshift for shift; calling array.unshift() with zero arguments is almost always a mistake, and I'd like it to tell me that.
interface Array<T> {
/**
* @deprecated You probably meant to use `.shift()`
*/
unshift(): number;
/**
* Inserts new elements at the start of an array, and returns the new length of the array.
* @param items Elements to insert at the start of the array.
*/
unshift(...items: T[]): number
}
Configuration Check
My compilation target is ESNext and my lib is the default.
Missing / Incorrect Definition
Array.prototype.unshift
Sample Code
const myArray = ["abc"];
// This should error / warn, as this is almost definitely a mistake
myArray.unshift()
// This should be ok even though the array might have zero elements
myArray.unshift(...myOtherArray)
Documentation Link
Not fully relevant: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
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 la dichiarazione della libreria standard per Array.prototype.unshift identificata dall'issue e verifica le convenzioni degli overload vicini. Controlla i test esistenti di verifica dei tipi per i metodi degli array; il lavoro è completato quando una chiamata diretta senza argomenti viene segnalata, mentre lo spread di un altro array rimane valido.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100