microsoft / microsoft/TypeScript
Suggestion: shorthand syntax for annotating function with type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
I like to define types for my functions by separating the type out from the value:
type id = <A>(a: A) => A;
const id: id = a => a;
This helps particularly for longer functions where the parameter list often spans many columns and multiple lines.
However, compared to Elm/Haskell, this code is quite boilerplate-y. I wonder if there is some shorthand syntax we could add to make this pattern more concise. For example, the same code in Elm/Haskell:
id : a -> a
id a = a
The boilerplate in the current TypeScript syntax is:
- Manual annotation of value (
id) with type of same name (id). Could this be automatic, e.g. matched by name? - TypeScript requires parameter names for the function type, but are these always required? Could the function type simply by
A => A, omitting the parameter names? Or would this cause problems?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia confrontando la sintassi abbreviata TypeScript proposta con gli esempi Elm e Haskell nell'issue. Definisci la sintassi accettata e il relativo comportamento nel controllo dei tipi prima di identificare le posizioni dell'implementazione e dei test; l'issue non specifica file, punti di ingresso o un criterio concreto di completamento.
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