Skip to content

[Feature Request] full support UMD module for tscΒ #46442

Closed
@John0King

Description

@John0King

Suggestion

πŸ” Search Terms

βœ… Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

ts is support UMD module , but not UMD bundle. Vue ,React and other package is using UMD and webpack to release their js base packages, but we come to typescript , you must need webpack and rewrite types for browse base code(sync load with <script> tag)

and follow feature to implement this goal:

  • declaration merge eg. bundle declaration files
  • entryfile in tsconfig.json
  • umdModuleName in tsconfig.json , this will pack every exported variable in entryfile to this namespace
  • dependency bundle and dependency exclude (preload dependency and self-contained dependency)
  • umdBundle of boolean in tsconfig.json (outFile can do this)
  • declaration for umdModuleName, ability to generate and also be used by typescript as well ( global variable access and type consume ) see code below
// lib.d.ts
export declare class Foo{
    sayHello():string;
    createNewFoo():Foo;
}
declare global
{
     declare let foo:Foo;
}
// main.ts  none module

foo.sayHellow

let myFoo:Foo = null ; // error, where is Foo class ?  import Foo from "lib" , will cause  exports.__esModule == true 
// and break `<script>` load in browse; <reference path />  won't load this type
if(true) // somcondition
{
    myFoo = foo.createNewFoo();
}

πŸ’» Use Cases

generate a umd bundle and can be use either browse <script> and other loader (eg. webpack, amd,CommonJS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions