microsoft / microsoft/TypeScript

Suggestion: disallow synthetic imports for ES modules

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

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

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

説明

TypeScript Version: 3.6.3

Search Terms: allowSyntheticDefaultImports esModuleInterop babel synthetic es modules default exports imports commonjs

Code

allowSyntheticDefaultImports is great when you're importing a CommonJS module, where/when Babel/TS will make sure there is a default export/import via their "interop" layers (e.g. esModuleInterop).

// foo.js
exports.foo = () => {}
// foo.d.ts
declare const _default: { foo: () => {} }
export = _default
// main.ts
import Foo from './foo';
Foo.foo(); // all good!

However, it's possible to shoot yourself in the foot by trying to import a non-existent default from an ES module.

// foo.js
export const foo = () => {}
// foo.d.ts
export declare const foo: () => {}
// main.ts
import Foo from './foo'; // no error, but should be `* as Foo`!
// runtime error!!
// TypeError: Cannot read property 'foo' of undefined
Foo.foo();

Ideally it would not be possible to use synthetic default imports with an ES module, so runtime errors such as the one above would not happen.

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

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

はじめの一歩

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

調査の方向性

allowSyntheticDefaultImports が ES モジュールからの default import を受け入れることを示す TypeScript 3.6.3 の再現コードから始め、CommonJS の例と比較してください。ES モジュールからの無効な default import が拒否され、意図された CommonJS の synthetic-default ケースは引き続きサポートされれば完了です。

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

評価

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

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

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