microsoft / microsoft/TypeScript

Type JS's `arguments` object based on function parameters

Aperta
#29,055 9 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Search Terms

type "arguments" object parameters

Suggestion

Within a function x, the type of the arguments object should be Parameters<typeof x> & IArguments, with undefined removed from the type of any entries in Parameters<typeof x> if that parameter has a default value.

Use Cases

class A {
   fn(it: number) { return true; }
}

class B extends A {
  fn(it: number) {
    // this shouldn't error, because arguments must be at least length 1.
    // instead we get ERROR: Expected 1 arguments, but got 0 or more.
    return super.fn(...arguments); 
  }
}

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

Non viene indicato alcun file sorgente, test o punto di ingresso del compilatore. Inizia riproducendo l'esempio di classe A/B e verifica come vengono attualmente controllati l'oggetto arguments, Parameters<typeof x>, i parametri predefiniti e super.fn(...arguments); il lavoro è completato quando l'esempio non segnala più l'errore sul numero di argomenti indicato, preservando al contempo il comportamento a runtime.

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

Valutazione

Stack tecnologico
javascript, 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
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.