Title: SystemJS and `default` import with `export =` proposal · Issue #5285 · microsoft/TypeScript · GitHub
Open Graph Title: SystemJS and `default` import with `export =` proposal · Issue #5285 · microsoft/TypeScript
X Title: SystemJS and `default` import with `export =` proposal · Issue #5285 · microsoft/TypeScript
Description: I was recently running into some trouble with getting SystemJS to load jQuery using the ES6-style syntax. import * as $ from 'jquery'; The above code worked fine with RequireJS and AMD format, and when using SystemJS as the loader when m...
Open Graph Description: I was recently running into some trouble with getting SystemJS to load jQuery using the ES6-style syntax. import * as $ from 'jquery'; The above code worked fine with RequireJS and AMD format, and ...
X Description: I was recently running into some trouble with getting SystemJS to load jQuery using the ES6-style syntax. import * as $ from 'jquery'; The above code worked fine with RequireJS and AMD form...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5285
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SystemJS and `default` import with `export =` proposal","articleBody":"I was recently running into some trouble with getting SystemJS to load jQuery using the ES6-style syntax.\n\n``` typescript\nimport * as $ from 'jquery';\n```\n\nThe above code worked fine with RequireJS and AMD format, and when using SystemJS as the loader when my code was emitted by TypeScript in AMD format.\n\nHowever I noticed odd behavior when emitting this code using the system format and using SystemJS. I was getting all of the static functions of `$`, but `$` _itself_ was an inert object (not a function). So at runtime, `$.isArray([]);` would work, but `$('#myDiv')` would throw \"$ is not a function\".\n\nHere's my original issue on the SystemJS repo: https://github.com/systemjs/systemjs/issues/844\n\nI kept digging around in the SystemJS documentation and eventually noticed that it referenced using a _default_ ES6 import with jQuery:\n\n``` typescript\nimport $ from 'jquery';\n```\n\nSure enough when I tried this, it worked, even though jQuery itself **does not** export a property `default`.\n\nAfter more research, I found this on the SystemJS site:\n\nhttps://github.com/systemjs/systemjs/blob/master/docs/module-formats.md#inter-format-dependencies\n\n> When loading CommonJS, AMD or Global modules from within ES6, the full module is available at the default export which can be loaded with the default import syntax.\n\nSo when using SystemJS, the \"is a\" is made available through a _virtual_ default export.\n\nHowever, this is a problem since there's not currently a way to model this in TypeScript without breaking existing code using `import $ = require('jquery')` syntax.\n\nCurrent jQuery definition on Definitely Typed:\n\n``` typescript\ndeclare module \"jquery\" {\n export = $;\n}\n```\n## Proposal\n\nIn light of the documented behavior of SystemJS, I'd like to propose a change to TypeScript to allow ES6-style default import syntax to work with an ambient external module declaration that uses `export =` syntax, as long as the module format is \"system\".\n\nWith this change, this code would compile cleanly if TypeScript is set to \"system\", but would still error using \"amd\", \"commonjs\" or \"umd\" with \"Module 'my-module' has no default export\":\n\n**my-module.d.ts**\n\n``` typescript\ndeclare module \"my-module\" {\n var doStuff : () => void;\n export = doStuff;\n}\n```\n\n**test.ts**\n\n``` typescript\nimport ds from \"my-module\";\nds();\n```\n\nRelated:\nhttps://github.com/Microsoft/TypeScript/issues/4337\nhttps://github.com/Microsoft/TypeScript/issues/2719\nCC: @vvakame @basarat @johnnyreilly @jbrantly @guybedford\n","author":{"url":"https://github.com/nycdotnet","@type":"Person","name":"nycdotnet"},"datePublished":"2015-10-16T16:22:21Z","url":"https://github.com/microsoft/TypeScript/issues/5285"}
| 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:163638bb-cb9f-719f-bd01-953ebdf1a06b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEA8:A99C2:19644C6:205C1B5:6B01327D |
| html-safe-nonce | 57e6b918565c7f127909fe94a13d2ad93af93cb6a7e5c20d48a76a8a5c7d7eba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUE4OkE5OUMyOjE5NjQ0QzY6MjA1QzFCNTo2QjAxMzI3RCIsInZpc2l0b3JfaWQiOiI3MDc5MDQ1NjI5Njk5MjQwNTczIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 83ebce72b95e10e59165914e305eba2574b82898ca09490c5f88f2a52d403f22 |
| hovercard-subject-tag | issue:111864080 |
| 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/5285/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6173334fc79cba6bb77580fa1ea77300bde535d811a86ffa20eda70e39d07be6/microsoft/TypeScript/issues/5285 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6173334fc79cba6bb77580fa1ea77300bde535d811a86ffa20eda70e39d07be6/microsoft/TypeScript/issues/5285 |
| og:image:alt | I was recently running into some trouble with getting SystemJS to load jQuery using the ES6-style syntax. import * as $ from 'jquery'; The above code worked fine with RequireJS and AMD format, and ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nycdotnet |
| 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