microsoft / microsoft/TypeScript
`import './file.json'`: This module is declared with using 'export ='
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
In short, JSON files's implied type definition is always defined via export =, even if I'm using module: es2015, causing it to error unless I use an unnecessary flag (allowSyntheticDefaultImports)
TypeScript Version: 3.9.0-dev.20200326
Search Terms:
import require json module commonjs es2015
Code
import list from "./list.json";
for (const item of list) {
console.log(item)
}
{
"compilerOptions": {
"outDir": "distribution",
"target": "es2017",
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true
},
"files": [
"index.ts"
]
}
Expected behavior:
list is of type string[]
Actual behavior:
index.ts:1:8 - error TS1259: Module '"./list"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
1 import list from "./list.json";
~~~~
list.json:1:1
1 [
~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
Found 1 error.
Workaround:
allowSyntheticDefaultImports: trueworks as expected, but that flag is unsafe and I don't want (need) to use it.-
declare module './list.json' { const list: string[]; export default list; }
Playground Link: repro.zip
Related Issues: https://github.com/microsoft/TypeScript/issues/15146
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にリンクされている repro.zip から始め、特に index.ts、list.json、および resolveJsonModule と module: es2015 の tsconfig 設定を確認してください。関連する issue #15146 と動作を比較してください。完了条件は、allowSyntheticDefaultImports なしで示されている default import の型チェックが通り、list が string[] として推論されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100