microsoft / microsoft/TypeScript

`typeof class`

Offen
#41,581 2 Kommentare 43 Reaktionen 2 zugewiesene Personen Auf GitHub ansehen

@ahejlsberg arbeitet bereits daran.

Seit 18.11.2020.

Awaiting More Feedback Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

@ahejlsberg has had a few experiments to try to make it easier to describe the type of a class. Specifically:

  • avoiding the awkward static/instance pattern that users need to write on anonymous object types/interface types

    var Thing: {
      new () => {
        instanceField: number;
      }
      staticField: string;
    }
    
  • allowing users to describe types with class-specific characteristics (e.g. abstract)

The idea is to allow typeof to be followed by a class expression.

var Thing: typeof class Thing {
  static staticField: string;

  instanceField: number;
  constructor() {}
}

There are definitely some subtleties here. For example, handling loops and whether this syntax is allowed in JSDoc with a TypeScript-annotated class:

/** @type { typeof class C<T> { x: T } } */
//                        ^^^    ^^^
// TypeScript type parameters and annotations
// Are these allowed?
var Thing;

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.