microsoft / microsoft/TypeScript
Suggestion: shorthand syntax for annotating function with type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the proposed TypeScript shorthand with the Elm and Haskell examples in the issue. Define the accepted syntax and its type-checking behavior before identifying implementation and test locations; the issue does not specify files, entry points, or a concrete completion criterion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100