microsoft / microsoft/TypeScript
generate function declaration from function type in TypeScript
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
From @unional on October 5, 2017 18:52
type MyCallback = (a: number, b: string) => void
function foo(callback: MyCallback) {
// ...
}
// case 1
foo((a, b) => { ... })
// case 2
foo(function (a, b) { ... })
// case 3
function cb(a: number, b: string) { ... }
foo(cb)
Above are 3 common ways to write a callback.
TypeScript is great at inferring the argument types in the implemented callbacks.
a, and b are typed accordingly in the callbacks above.
However, the tooltip is not useful when we are implementing the callbacks:

If I change foo() to not using type alias, it helps in case 1 and 2:
function foo(callback: (a: number, b: string) => void) { ... }

But that doesn't help in case 3 and actually demotes type alias.
One solution I can think of is using [ctrl+.] to fill in the callback:
foo(/* caret */)
// [ctrl+.] and choose "implement callback as arrow function":
foo((a: number, b: string) => { /* caret */ })
// [ctrl+.] and choose "implement callback as function declaration":
foo(function (a: number, b: string) { /* caret */ })
// caret anywhere on the type alias below
MyCallback
// [ctrl+.] and choose "implement function declaration" will expand to snippet:
function ${1:functionName}(a: number, b: string): void { ${0} }
Copied from original issue: Microsoft/vscode#35635
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では実装ファイルやテストが指定されていません。まず、callback と function-declaration の生成に対応する ctrl+. の code-action エントリーポイントをたどり、その後、要求されたアクションが3つすべての例で推論された callback パラメーターと type aliases をサポートしていることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100