microsoft / microsoft/TypeScript

Add a compiler option to error on destructuring a string as an array

Aperta
#61,106 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

🔍 Search Terms

string destructuring

✅ Viability Checklist
⭐ Suggestion
{
  "compilerOptions": {
    "allowDestructureStringAsArray": false
  }
}
declare const source: string
const [item] = source
//        ^^^^^ Error: destructuring string as array is not allowed
📃 Motivating Example

The codebase is everchanging. Someone might do a refactor that change an expression from returning an array of strings to returning a single string. TypeScript which was supposed to catch mistakes like this would fail.

-return Object.entries(myObject)
+return Object.keys()
   .sort(([k1], [k2]) => k1.localeCompare(k2))

As you can see in the above example, the developer forgot to also update the .sort line, but TypeScript didn't alert it. This mistake is easy to catch in small code, but real code is much bigger and similar mistake would be harder to detect.

💻 Use Cases
  1. What do you want to use this for? Catching mistake during refactoring or code editing.
  2. What shortcomings exist with current approaches? There is no "current approaches".
  3. What workarounds are you using in the meantime? There is no workaround, eslint doesn't have such rule, and I doubt it cares about TypeScript's types.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Nell’issue non sono indicati file, test o punti di ingresso del compilatore. Inizia tracciando come vengono definite le opzioni del compilatore e come viene verificato il tipo del destructuring di array. Il lavoro è completato quando una nuova opzione può rifiutare il destructuring di una stringa come array, mantenendo il comportamento esistente per impostazione predefinita, con una copertura per l’esempio mostrato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.