microsoft / microsoft/TypeScript

Inferred missing properties use resolved generic types rather than staying generic

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

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

Domain: LS: Quick Fixes Experience Enhancement Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: 3.3.0-dev.20181212

Search Terms: declare property generic missing member

Code

class TestClass<T> {
    // Inferred:
    // otherValue: number;
    public constructor(
        public readonly value: T,
    ) { }
}


const foo = new TestClass<number>(1);

foo.otherValue = foo.value;

Expected behavior:

Declare property 'otherValue' should create otherValue: T;

Actual behavior:

...but it actually creates otherValue: number. Whatever generic type from the place you request the missing property be added will be the type of the property.

Playground Link: http://www.typescriptlang.org/play/#src=class%20TestClass%3CT%3E%20%7B%0D%0A%20%20%20%20%2F%2F%20Inferred%3A%0D%0A%20%20%20%20%2F%2F%20otherValue%3A%20number%3B%0D%0A%20%20%20%20public%20constructor(%0D%0A%20%20%20%20%20%20%20%20public%20readonly%20value%3A%20T%2C%0D%0A%20%20%20%20)%20%7B%20%7D%0D%0A%7D%0D%0A%0D%0A%0D%0Aconst%20foo%20%3D%20new%20TestClass%3Cnumber%3E(1)%3B%0D%0A%0D%0Afoo.otherValue%20%3D%20foo.value%3B%0D%0A

Related Issues: I found a lot of similar bugs but didn't see any that looked related...

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

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

はじめの一歩

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

調査の方向性

提供された TypeScript playground の再現コードを typescript@next で開始し、その挙動が引き続き発生するか確認してください。ジェネリッククラスとインスタンス化された値から、欠落しているプロパティがどのように推論されるかを追跡してください。宣言されたプロパティが number に解決されるのではなく、ジェネリック型 T を保持し、例をカバーするリグレッションテストがあることを完了条件とします。

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

評価

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

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

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