You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)