microsoft / microsoft/TypeScript

type callbacks

Offen
#29,755 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

search: https://www.google.com/search?q=type+functions+site%3Ahttps%3A%2F%2Fgithub.com%2FMicrosoft%2FTypeScript

The more I work with advance types the more apparent the following problems become:

No intermediate types

At the current stage the advanced types are represented via expressions. Quite often there is a need to reuse exactly the same part of such expression in more than one place. Currently there is no way to capture a part of it and reuse it, consider:

type A<X> = { x: B<X>, y: B<X> }

here I wish I could save B<X> into a local type C somehow to be able to write

// speculative syntax:
type A<X> = <
    type C = B<X>;
    { x: C, y: C };
>;

per @RyanCavanaugh intermediate types are covered by https://github.com/Microsoft/TypeScript/issues/23188

No way to specify a type callback

Currently type parameters are the only way to define a parametric type. There is no way to define a type based on a type callback:

interface Z { x: string; y: number; }
// speculative syntax:
type A<T, F: X =>...,  T> =  { [P in keyof T]: F<T[P]>; } // <-- wish could do this
type B = A<Z, X => X extends string ? true : false>;  // { x: true; y: false; }
type C = A<Z, X => { get: () => X }>;  // { x: { get: () => string; }; y: { get: () => number; }; }

I am not sure what a proposal would be, but these problems are definitely worth a discussion

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.

Rechercherichtung

Beginnen Sie damit, die in diesem Issue vorgeschlagenen Beispiele für type-callbacks und das verlinkte Issue #23188 zu lesen, das Zwischentypen behandelt. Das Issue nennt keine Implementierungsdateien oder Tests und fordert eine Diskussion statt einer definierten Änderung. Eine abgeschlossene Arbeit würde einen vereinbarten Vorschlag dafür erfordern, wie type-callbacks ausgedrückt und angewendet werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

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