microsoft / microsoft/TypeScript

Provide `declare` keyword support for class methods

Aperta
#38,008 6 commenti 12 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

declare, class, method

Suggestion

I know that declare keyword already support class properties. I've wonder if it is possiable to bring the support to class methods as well?

Use Cases

You override a method a, and there are some other methods that return the return value of a.

Examples

This is just a simple example describing my idea.

class BaseTag
{
    constructor(tag: string) {...}

    static fromString(tag: string): BaseTag
    {
        return new BaseTag(tag);
    }

    static fromNumber(tag: number): BaseTag
    {
        return this.fromString(tag.toString());
    }
}

class ExtendedTag extends BaseTag
{
    static fromString(tag: string): ExtendedTag
    {
        return new BaseTag(`Tag: ${ tag}`);
    }

    declare static fromNumber(tag: number): ExtendedTag;

    // // Without `declare` support
    // static fromNumber(tag: number): ExtendedTag
    // {
    //     return super.fromString(tag) as unknown as ExtendedTag;
    // }
}

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

L’issue non indica alcun file sorgente, test o punto di ingresso. Inizia confrontando il supporto esistente di declare per le proprietà di classe con la sintassi richiesta per i metodi statici e chiarisci il relativo comportamento di type-checking ed emissione. L’attività è completata quando la semantica della funzionalità è specificata e coperta da test.

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.