Title: Proposal: Modularize Library · Issue #6974 · microsoft/TypeScript · GitHub
Open Graph Title: Proposal: Modularize Library · Issue #6974 · microsoft/TypeScript
X Title: Proposal: Modularize Library · Issue #6974 · microsoft/TypeScript
Description: Problem Currently TypeScript compiler accepts a single compiler option, target, which specify both version of library to be included during compilation and version of JavaScript for emitting code together. The behaviour presents limitati...
Open Graph Description: Problem Currently TypeScript compiler accepts a single compiler option, target, which specify both version of library to be included during compilation and version of JavaScript for emitting code t...
X Description: Problem Currently TypeScript compiler accepts a single compiler option, target, which specify both version of library to be included during compilation and version of JavaScript for emitting code t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6974
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Modularize Library","articleBody":"# Problem\n\nCurrently TypeScript compiler accepts a single compiler option, `target`, which specify both version of library to be included during compilation and version of JavaScript for emitting code together.\nThe behaviour presents limitations in two parts of the pipeline: consuming the default library and granularly controlling how JavaScript will be emitted (e.g. what features to be down-level etc.).\nThe proposal will mainly focus on the first issue regarding using the default library.\n\nThe current behavior of `target` option doesn't allow users to have a fine-grain control on what library or feature of the library to be included, and user cannot independently control library's version from emit JavaScript version. As summarized in [#4692](https://github.com/Microsoft/TypeScript/issues/4692) _Proposal: Granular Targeting_ and [#4168](https://github.com/Microsoft/TypeScript/issues/4168) _Normalize our lib files by compiler setting_\n- Emit ES5 JavaScript while using ES6 library during design-time (and vice-versa).\n- Include only sub-part of the ES6/ESnext library\n- Modifying default libraries can conflict with users-defined ones.\n- Using host-specific library.\n## Workaround\n\nAs @yortus points out in the [#4692](https://github.com/Microsoft/TypeScript/issues/4692) _Proposal: Granular Targeting_ , there are possible workarounds for above issues by maintaing customized version of the default library while `target` another version of emit JavaScript.\nSuch approach is cumbersome to maintain and consume any necessary fixes of the default library.\n## Related Issues:\n- [#4692](https://github.com/Microsoft/TypeScript/issues/4692) Proposal: Granular Targeting\n- [#4168](https://github.com/Microsoft/TypeScript/issues/4168) Normalize our lib files by compiler settings\n- [#3215](https://github.com/Microsoft/TypeScript/issues/3215) New APIs added to lib.d.ts may break client codes. Allow duplicated members in interfaces? Make lib.d.ts overridable?\n- [#3005](https://github.com/Microsoft/TypeScript/issues/3005) Using ES6 type default library when targetting ES5 output\n# Proposed Solution\n\nThere are two parts to the proposed solution:\n1. Introducing a new compiler flag `--lib`. The flag will be used to allow users to granularly control the default library.\n Note: `target` flag will remain. Its behaviors with `--lib` flag will be discussed below.\n2. Breaking down the default library into smaller files, especially ES6 library and any future JavaScript library.\n## Compiler Flag `--lib`\n\nThe flag's options (see below for the full list) allows users to specify what library to be included into the compilation.\nThe flag's options can be separated into following categories:\n- JavaScript only:\n \n es3\n \n es5\n \n es6\n- Host only:\n \n node\n \n dom\n \n dom.iterable\n \n webworker\n \n scripthost\n- ES6 or ESNext by-features options:\n \n es6.array\n \n es6.collection\n \n es6.function\n \n es6.generator\n \n es6.iterable\n \n es6.math\n \n es6.number\n \n es6.object\n \n es6.promise\n \n es6.proxy\n \n es6.reflect\n \n es6.regexp\n \n es6.string\n \n es6.symbol\n \n es6.symbol.wellknown\n \n es7.array.include\n\nThe `--lib` flag is an optional flag and multiple options can be used in combination (e.g `--lib es6,dom.iterable`) and each option will be mapped to associated library.\nSo in this example, files: `lib.es6.d.ts` and `lib.dom.iterable.d.ts` will be loaded into the compilation..\nWhen `--lib` is specified, `--target` will be used solely to indicate version of emitting JavaScript.\n\nIn additional to above behavior, we still need to determine what to be included when `--lib` is not specified, should it remain the same, including version of library specifying by `--target` and all host libraries, or including every library. -> _Current implementation is to include version of the library using `--target`\n\nThe proposal will only affect when the compiler attempts to create compilation in Program.ts. Other parts of the pipeline will not be affected by the proposal.\n# Usage:\n\nThe `--lib` flag will take an options in the form of string separated by comma. Space will not be allowed as a separator. This rule apply to both command line and tsconfig\n\nValid\n\n``` bash\ntsc --target es5 --lib es6\ntsc --target es5 --lib es5,es6.array\n```\n\n``` json\n\"compilerOptions\": {\n ...\n \"lib\": \"es5,es6.array\"\n}\n```\n\nInvalid command-line\n\n``` bash\ntsc --target es5--lib es5, es6.array // es6.array will be considered a file-name\ntsc --target es5 --lib es5 es6.array // es6.array will be considered a file-name\n```\n\n``` json\n\"compilerOptions\": {\n ...\n \"lib\": \"es5, es6.array\"\n}\n```\n# Working Items:\n- [X] Breaking up the library (PR #6990, this PR is folded into #6974)\n- [X] Adding compiler options (PR #6974)\n- [X] Language Service support in VS\n- [ ] Add node.d.ts and browser.d.ts\n","author":{"url":"https://github.com/yuit","@type":"Person","name":"yuit"},"datePublished":"2016-02-09T03:06:25Z","url":"https://github.com/microsoft/TypeScript/issues/6974"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e8ef78a9-c545-adfc-dc4f-f283daee7bca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A01E:34DB8F:2262757:2DF31EF:6B019759 |
| html-safe-nonce | b6cd2d15f8711e4e9de0adaba68efc24a2ffb1abaeef04768e7693450f0d5528 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDFFOjM0REI4RjoyMjYyNzU3OjJERjMxRUY6NkIwMTk3NTkiLCJ2aXNpdG9yX2lkIjoiNjgzNzI2MjY5NjMzMzgwOTQ5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6acfd0e678f09ce4eb84895062c02ee8ab71d298a733c440e535ef46db3bbffb |
| hovercard-subject-tag | issue:132320081 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/6974/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9df9cce94c86769c564a5ed50cf55606b97f58cb07495c8710b68d1ec77fd3ce/microsoft/TypeScript/issues/6974 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9df9cce94c86769c564a5ed50cf55606b97f58cb07495c8710b68d1ec77fd3ce/microsoft/TypeScript/issues/6974 |
| og:image:alt | Problem Currently TypeScript compiler accepts a single compiler option, target, which specify both version of library to be included during compilation and version of JavaScript for emitting code t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yuit |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width