microsoft / microsoft/TypeScript
Add refactoring option to convert between function declaration and function variable
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
- refactor function declaration
- refactor to arrow function
Suggestion
Consider adding refactoring from
const fn = (x: number): number => {
return x + 1
}
into
function fn(x: number): number {
return x + 1
}
and vice-versa.
Use Cases
I found myself doing this refactor by hand many times. I think the main use cases are:
- Project has code style which enforces one of the above, and you're pasting some other code.
- Particular function declaration simply looks better when written as block-less arrow function.
- After refactoring an arrow function to a variable in current scope, it always picks the arrow style, but it could be written as a declaration as well.
Examples
Don't know if viable, but here it goes:
export const Component: React.FC<Props> = props => {
return <h1>Hello, {props.name}</h1>
}
export function Component(props: Props) {
return <h1>Hello, {props.name}</h1>
}
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にはファイル、テスト、エントリポイントが記載されていません。まず、関数宣言と関数変数に対する既存のリファクタリングサポートを見つけ、次に、両方向で示されているパラメーター、戻り値の型、エクスポート、JSX の使用方法をどのように維持すべきかを判断してください。両方の変換がリファクタリングアクションとして利用でき、例示されている TypeScript および TSX のケースがカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- developer-experience, devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100