Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: shorthand syntax for annotating function with type #16334

Open
OliverJAsh opened this issue Jun 7, 2017 · 1 comment
Open

Suggestion: shorthand syntax for annotating function with type #16334

OliverJAsh opened this issue Jun 7, 2017 · 1 comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Jun 7, 2017

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?
@mhegazy mhegazy added the Needs Investigation This issue needs a team member to investigate its status. label Aug 29, 2017
@thorn0
Copy link

thorn0 commented Oct 26, 2017

For a discussion about parameter names, see #13152,

@mhegazy mhegazy added Suggestion An idea for TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Oct 26, 2017
@RyanCavanaugh RyanCavanaugh added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants