-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Suggestion
🔍 Search Terms
- UMD output option for single file #6380
- umd module compiler option doesn't have a fallback for global namespace. #8436
- Completions are low-quality for UMD modules without typings #20565
- Error when augmenting UMD module #13565
- Proposal: Bundling TS module type definitions #4433
✅ 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.jsonumdModuleName
in tsconfig.json , this will pack every exported variable inentryfile
to this namespace- dependency bundle and dependency exclude (preload dependency and self-contained dependency)
(outFile can do this)umdBundle
of boolean in tsconfig.json- 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)
aersam, Dan503, Lazerbeak12345, kldzj, adamjeffries and 2 more
Metadata
Metadata
Assignees
Labels
Out of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript