microsoft / microsoft/TypeScript

Provide TypeScript as an ESM

Offen
#32,949 0 Kommentare 48 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

commonjs, esm, lib/typescript

Suggestion

Currently lib/typescript.js and other lib files do not support being loaded as ES modules. They only support loading as a global script or a CommonJS module.

Use Cases

For runtimes that want to load TypeScript as a module and not in the global namespace, they have to do some pre-processing using a packager like webpack, rollup, etc. to be able to load TypeScript as an ES Module.

In addition, there are useful CDNs like Pike which can parse npm packages, find the ES modules, and will host an optimised version designed for loading in greenfield modern/browsers.

Examples

For example, it is impossible to currently load lib/typescript.js in Deno as it only supports ESM and each import is assumed to be a module, and therefore the var ts is scoped to the module. Also loading directly as a module in a browser would be possible.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Untersuchung von lib/typescript.js und den anderen in der Issue erwähnten lib-Dateien und konzentriere dich darauf, wie sie derzeit als globale Skripte oder CommonJS-Module geladen werden. Ermittle die Anforderungen zum Laden von ESM für Deno und Browser; abgeschlossen ist die Aufgabe, wenn TypeScript direkt als ES-Modul ohne Vorverarbeitung geladen werden kann und das bestehende JavaScript-Verhalten weiterhin unterstützt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
developer-experience, tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.