microsoft / microsoft/TypeScript

Suggest argument names based on type definition of callback functions

Aperta
#40,335 1 commento 5 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

callback, arguments, parameters, suggestion, auto correct

Suggestion

Let's say I have a type definition for my function like this:

function acceptsCallback(callback: (argumentNameThatIsVeryLong: string) => void) {}

When using it, that argumentNameThatIsVeryLong is a very good candidate for my argument name. I want to accept it but there is no way but typing it:

Screen Shot 2020-08-31 at 5 22 34 PM

Use Cases

When users are extremely lazy this is very handy! ;) In all seriousness this can avoid bugs by suggesting the right argument name. For instance when req and res objects are misplaced in an Express middleware by mistake

Examples

https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAQwhApgBygZwMLIA2hARqgNYAUERpFAXIpcgE4DmIAtumFAHLJuAFQAWyKAEkcANXQsAngBkEbRjigsYYNgEpEAXgB8iAG5wYAEz0BvAL4Aoe6gzZ8tMhCqPv95ux32OkA

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 sono indicati file di implementazione né test. Inizia dall’esempio collegato di TypeScript Playground e verifica come si comportano attualmente nell’editor i suggerimenti per i parametri di callback. Il lavoro è completato quando i nomi degli argomenti di una definizione di tipo callback vengono offerti come suggerimenti senza modificare il JavaScript emesso.

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

Valutazione

Stack tecnologico
javascript, typescript
Ambito
developer-experience, tooling
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.