microsoft / microsoft/TypeScript

"Import assignment cannot be used when targeting ECMAScript modules." should come with a codefix

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

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

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

説明

TypeScript Version: 3.2.0-dev.20181030

Code

a.ts

import abs = require("abs");

tsconfig.json

{
    "compilerOptions": {
        "target": "esnext"
    }
}

The error message is Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.. This indicates that we could provide a code fix.

Expected behavior:

There is a codefix that offers to change this to import abs from "abs";, or import * as abs from "abs";. If --esModuleInterop is set and the imported value is not used only as a namespace, we should prefer a default import.

Actual behavior:

No codefix.

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

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

はじめの一歩

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

調査の方向性

a.ts と示されている tsconfig.json を使って診断を再現し、このエラーに対するコンパイラの codefix 処理を追跡します。修正では default import と namespace import の形式を提示し、esModuleInterop が有効で、値が namespace としてのみ使用されていない場合は default import を優先する必要があります。提案された両方の編集と、それらの適用可能性を確認してください。

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

評価

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

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

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