microsoft / microsoft/TypeScript

refactoring for extracting return type of a function

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

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

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

説明

Search terms

refactoring extract return type function method interface inferred

Suggestion

A new refactoring for function expressions that extracts the return type of the function as an interface or type.

Use Cases

Imagine a complex function that combines many types of data into a complex object. Compiler can infer the return type, but writing it out by hand takes time. Type needs a name when you want to use it elsewhere in the code (for example as a parameter type for another function).

Examples

Imagine A, B, C, D are non trivial types. (e.g. objects with many properties)

before:

function fooFunc(a: A, b: B, c: C, d: D) {
  return {
    ...a,
    ...b,
    foo: {...c, d}
  }
}

after:

type FooFuncReturn = A & B & { foo: C & D }
// or when possible an interface type with would be even better

function fooFunc(a: A, b: B, c: C, d: D): FooFuncReturn {
  return {
    ...a,
    ...b,
    foo: {...c, d}
  }
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

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

はじめの一歩

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

調査の方向性

この Issue では、ファイル、テスト、エントリーポイントが示されていません。まず TypeScript に既存のリファクタリング基盤を見つけ、次に、要求されている戻り値の型の抽出で、例にある型とインターフェースの形式をどのように扱うかを定義してください。指定された関数式のユースケースでリファクタリングが機能し、その出力に対するテストカバレッジがあることを完了条件とします。

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

評価

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

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

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