microsoft / microsoft/TypeScript
Suggestion: disallow synthetic imports for ES modules
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der TypeScript-3.6.3-Reproduktion, die zeigt, dass allowSyntheticDefaultImports einen default import aus einem ES-Modul akzeptiert, und vergleiche sie mit dem CommonJS-Beispiel. Als erledigt gilt die Aufgabe, wenn der ungültige ES-Modul-default-import abgelehnt wird, während der vorgesehene CommonJS-synthetic-default-Fall weiterhin unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100