microsoft / microsoft/TypeScript

Named import for 'any'-typed module doesn't work

オープン
#42,506 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

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

説明

Bug Report

🔎 Search Terms

any module export assignment named import

🕗 Version & Regression Information

TypeScript v4.1.2

💻 Code

mock.d.ts

declare const _: any;
export = _;

example.ts

import { a } from "./mock";

import * as b from "./mock";
const { c } = b;

const { d } = await import("./mock");

console.log(a, c, d);

tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "strict": true,
    "target": "ESNext",
  },
  "include": [
    "./**/*.ts"
  ]
}
🙁 Actual behavior

The first import returns the diagnostic:

error TS2305: Module '"./mock"' has no exported member 'a'.

While c and d do not error.

🙂 Expected behavior

With an export being effectively any, I would expect default, namespace, dynamic and named imports to all behave as if the module was any. I cannot find any other way to declare a module in a fashion where the compiler treats any import from that module as any and does not issue diagnostics.

As implied in the above, there are certain situations where there is a need to "mock" a module where its shape cannot be statically determined at compile time.

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

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

はじめの一歩

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

調査の方向性

mock.d.ts、example.ts、tsconfig.jsonを使って報告内容を再現し、その後、TypeScriptコンパイラーがanyとして型付けされたexport-assignmentモジュールからの名前付きインポートをどのように処理するかを追跡します。名前付きインポートでTS2305が報告されなくなり、namespaceインポートとdynamicインポートについて示されている動作が維持されれば完了です。

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

評価

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

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

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