microsoft / microsoft/TypeScript
Suggestion: disallow synthetic imports for ES modules
まだ誰も着手していません。
- 主要言語
- 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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