microsoft / microsoft/TypeScript

Suggestion: shorthand syntax for annotating function with type

オープン
#16,334 コメント 1 件 リアクション 19 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提案されている TypeScript の短縮構文を、issue 内の Elm および Haskell の例と比較します。実装箇所とテスト箇所を特定する前に、受け入れられる構文とその型チェック時の動作を定義してください。issue では、ファイル、エントリーポイント、具体的な完了基準が指定されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
20/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。