microsoft / microsoft/TypeScript

--noImplicitAny codefixes infer anonymous object types despite appropriate interfaces in (or out of) scope

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

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 3.3.0-dev.20181212

Search Terms: noimplicitany infer code fix codefix quick suggested

Code

interface IBox {
    x: number;
    y: number;
}

const shiftBox = (box) => {
    box.x += 1;
    box.y += 1;
}

const box = {
    x: 0,
    y: 0,
};

shiftBox(box);

Expected behavior:

--noImplicitAny suggested fix on the box parameter:

const shiftBox = (box: IBox) =>

Actual behavior:

const shiftBox = (box: { x: any; y: any; }) => {

Related Issues: #13243 (parent tracking quick fixes) and #15114 (discussion on inference difficulties)

If there is an interface available that can satisfy an inferred type in a --noImplicitAny code fix, can we use that? Perhaps with an ordering of possibilities like:

  1. Interfaces already available in the file, by how small they are
  2. User-defined interfaces that could be imported, by how distant the file is
  3. Module types already imported in a user file, by how distant the nearest import is

...where, if multiple interfaces could satisfy the best possibility of those three, we choose the one with the fewest fields?

In code bases that don't explicitly type when unnecessary (e.g. : IBox for variables), I'm finding the --noImplicitAny fixes to be a bit useless for anything other than primitives.

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

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

はじめの一歩

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

調査の方向性

提供された TypeScript の例から始め、--noImplicitAny codefix の出力を再現してください。提案されているインターフェイス選択ルールを理解するため、関連する issue #13243 と #15114 の議論を読んでください。互換性のある利用可能なインターフェイス(IBox など)が匿名オブジェクト型より優先され、他の codefix ケースを壊さなければ完了です。

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

評価

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

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

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