microsoft / microsoft/TypeScript

Allow overload signatures when writing class property initializers

Aperta
#33,750 8 commenti 10 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Search Terms

  1. typescript class bound function parameter overload
  2. typescript class bound function overload
  3. typescript class bound method overload
  4. typescript class bound arrow overload

Suggestion

It would be nice if we could overload bound arrow function methods in a class without the need to specifically declare a constructor and bind methods in it.

Use Cases

Examples

// existing valid implementation
// class `A` has method `a` bound to its instance in the constructor
class A {
  constructor(){
    this.a = this.a.bind(this);
  }

  a(a: string): string;
  a(a: string, b: string): string;
  a(a: string, b?: string): string {
    if(b) return a + b;
    return a;
  }
}

// suggested alternative implementation
// class `B` declares a bound arrow function `a` and its overloads without the need for a ctor
class B {
  a = (a: string): string;
  a = (a: string, b: string): string;
  a = (a: string, b?: string): string => {
    if(b) return a + b;
    return a;
  }
}

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 né alcun punto di ingresso dei test; inizia esaminando gli esempi proposti di overload di proprietà di classe e l'esempio esistente di overload associato al costruttore. Il lavoro sarà completato quando TypeScript accetterà la sintassi suggerita, manterrà il controllo dei tipi previsto e produrrà il JavaScript atteso senza richiedere un costruttore.

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.