microsoft / microsoft/TypeScript

--esModuleInterop: Strange incompatibility between correct and incorrect import of same type

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

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

Domain: Error Messages Experience Enhancement In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript Version: master

Code

b.d.ts

declare class C {
    f: this;
}
declare namespace C {}
export = C;

a.ts

import * as C1 from "./b";
import C2 = require("./b");

function f(t: (c: C1) => void): void {
    t(new C2());
}

Expected behavior:

Error at import * as C1.

Actual behavior:

No error at the import declaration. Error at new C2():

src/a.ts(5,7): error TS2345: Argument of type 'C' is not assignable to parameter of type 'C'.
  Types of property 'f' are incompatible.
    Type 'C' is not assignable to type 'this'.

(possibly related: #20704)

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

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

はじめの一歩

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

調査の方向性

b.d.ts と a.ts を示されているとおり正確に使って報告を再現し、その後 TypeScript checker を実行して new C2() での診断を確認します。まず、import * as C1、import-equals require、export =、および this 型付きプロパティがどのように比較されるかを追跡します。非互換性が一貫して処理され、診断の想定される位置または動作が回帰テストでカバーされれば完了です。

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

評価

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

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

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