microsoft / microsoft/TypeScript

type callbacks

Aperta
#29,755 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

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

Inizia leggendo gli esempi di type-callback proposti in questa issue e l’issue collegata #23188, che tratta i tipi intermedi. L’issue non indica file di implementazione né test e richiede una discussione anziché una modifica definita. Un lavoro completato richiederebbe una proposta concordata per esprimere e applicare i type-callback.

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
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.