René's URL Explorer Experiment


Title: Functions wrapped in `__importDefault` with allowSyntheticDefaultImports emit incorrect function calls · Issue #35420 · microsoft/TypeScript · GitHub

Open Graph Title: Functions wrapped in `__importDefault` with allowSyntheticDefaultImports emit incorrect function calls · Issue #35420 · microsoft/TypeScript

X Title: Functions wrapped in `__importDefault` with allowSyntheticDefaultImports emit incorrect function calls · Issue #35420 · microsoft/TypeScript

Description: The following code: import allSettled from "promise.allsettled"; const resolved = Promise.resolve(42); const rejected = Promise.reject(-1); allSettled([resolved, rejected]).then(results => { console.log(results); }); Is transpiled into t...

Open Graph Description: The following code: import allSettled from "promise.allsettled"; const resolved = Promise.resolve(42); const rejected = Promise.reject(-1); allSettled([resolved, rejected]).then(results => { consol...

X Description: The following code: import allSettled from "promise.allsettled"; const resolved = Promise.resolve(42); const rejected = Promise.reject(-1); allSettled([resolved, rejected]).then(results =...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/35420

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Functions wrapped in `__importDefault` with allowSyntheticDefaultImports emit incorrect function calls","articleBody":"The following code:\r\n\r\n```ts\r\nimport allSettled from \"promise.allsettled\";\r\n\r\nconst resolved = Promise.resolve(42);\r\nconst rejected = Promise.reject(-1);\r\n\r\nallSettled([resolved, rejected]).then(results => {\r\n  console.log(results);\r\n});\r\n```\r\n\r\nIs transpiled into the following JS with `esModuleInterop` & `allowSyntheticDefaultImports`:\r\n\r\n```js\r\n\"use strict\";\r\nvar __importDefault =\r\n  (this && this.__importDefault) ||\r\n  function(mod) {\r\n    return mod && mod.__esModule ? mod : { default: mod };\r\n  };\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst promise_allsettled_1 = __importDefault(require(\"promise.allsettled\"));\r\nconst resolved = Promise.resolve(42);\r\nconst rejected = Promise.reject(-1);\r\npromise_allsettled_1.default([resolved, rejected]).then(results => {\r\n  console.log(results);\r\n});\r\n```\r\n\r\nFull `tsconfig.json`:\r\n\r\n```js\r\n{\r\n  \"compilerOptions\": {\r\n    \"target\": \"es2018\",\r\n    \"module\": \"commonjs\",\r\n    \"strict\": true,\r\n    \"allowSyntheticDefaultImports\": true,\r\n    \"esModuleInterop\": true,\r\n  },\r\n  \"include\": [\r\n    \"src\"\r\n  ]\r\n}\r\n```\r\n\r\n([CodeSandbox](https://codesandbox.io/s/inspiring-lewin-eyt6r).)\r\n\r\nExecuting this code leads to:\r\n\r\n```\r\nTypeError: #\u003cObject> is not a constructor\r\n    at Object.resolve (\u003canonymous>)\r\n    at Object.PromiseResolve (/sandbox/node_modules/es-abstract/es2018.js:160:10)\r\n    at /sandbox/node_modules/promise.allsettled/implementation.js:26:24\r\n    at Function.from (\u003canonymous>)\r\n    at Object.allSettled (/sandbox/node_modules/promise.allsettled/implementation.js:19:22)\r\n    at Object.allSettled [as default] (/sandbox/node_modules/promise.allsettled/index.js:16:9)\r\n    at Object.\u003canonymous> (/sandbox/src/demo.ts:6:11)\r\n    at Module._compile (internal/modules/cjs/loader.js:776:30)\r\n    at Module.m._compile (/sandbox/node_modules/ts-node/src/index.ts:536:23)\r\n    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)\r\n```\r\n\r\nThat is because the promise.allsettled package handles `this` according to the spec, see https://github.com/es-shims/Promise.allSettled/issues/5. The author of that library is @ljharb who will have deeper understanding of the specifics than I do. (Also, thanks for nudging me to report this issue!)\r\n\r\nThe problem is most likely the emitted function call, which looks like this:\r\n\r\n```js\r\npromise_allsettled_1.default([resolved, rejected]).then(results => {\r\n  console.log(results);\r\n});\r\n```\r\n\r\nIn comparison, Babel + TS emits this (which works):\r\n\r\n```js\r\n(0, _promise.default)([resolved, rejected]).then(function (results) {\r\n  console.log(results);\r\n});\r\n```\r\n\r\n[Babel playground](https://babeljs.io/en/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=JYWwDg9gTgLgBAQwDZIMoFMYyegJnAMyghDgHIxiRgBndAOmSTqx1zIG4AoLgYwgB2NeFHQ0ISAG544AXjgAFKrQajxU9AAoALACYAlN35CR6AFbpeMGfKUkV9URauaAtAEZDPJhlZ5NANpqEtK4ADRwTpbWuAC6-vQwABboAppqAK5IMDRyAHxwAN5ccHDG6gxIEADm6WJZOV4AvoZAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.7.4&externalPlugins=).\r\n\r\n**TypeScript Version:**  3.7.2\r\n\r\n**Search Terms:** `esModuleInterop`, `allowSyntheticDefaultImports`, emit, transpile, downlevel compile, ES Modules, default, wrapper, Node.js, module.","author":{"url":"https://github.com/borekb","@type":"Person","name":"borekb"},"datePublished":"2019-11-29T10:31:28Z","url":"https://github.com/microsoft/TypeScript/issues/35420"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0ae107b8-a3bc-0935-3f90-cb2bd21ca265
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC150:10B16D:118B49C:1762175:6AED5946
html-safe-nonceb96287e5b07d6bf3a5af9775189e8ae9895bf25b0e1bb60eecf1b497134430ae
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTUwOjEwQjE2RDoxMThCNDlDOjE3NjIxNzU6NkFFRDU5NDYiLCJ2aXNpdG9yX2lkIjoiMTU5ODMzMDk3ODE2MzMxNzA2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca6d55065cabdb41c42973fa5c47d8e8ee0a2e33416c74172e77fbdf1e5dc2d72
hovercard-subject-tagissue:530272338
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/35420/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fa378ad4775c13acce1741f3399fd9b7eb386296ef14edb0965983361496230a/microsoft/TypeScript/issues/35420
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fa378ad4775c13acce1741f3399fd9b7eb386296ef14edb0965983361496230a/microsoft/TypeScript/issues/35420
og:image:altThe following code: import allSettled from "promise.allsettled"; const resolved = Promise.resolve(42); const rejected = Promise.reject(-1); allSettled([resolved, rejected]).then(results => { consol...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameborekb
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/35420#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F35420
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F35420
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/35420
Reloadhttps://github.com/microsoft/TypeScript/issues/35420
Reloadhttps://github.com/microsoft/TypeScript/issues/35420
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues4.9k (4.9k)https://github.com/microsoft/TypeScript/issues
Pull requests298 (298)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/pulse
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35420
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35420
#44624https://github.com/microsoft/TypeScript/pull/44624
#35877https://github.com/microsoft/TypeScript/pull/35877
Functions wrapped in __importDefault with allowSyntheticDefaultImports emit incorrect function callshttps://github.com/microsoft/TypeScript/issues/35420#top
#44624https://github.com/microsoft/TypeScript/pull/44624
#35877https://github.com/microsoft/TypeScript/pull/35877
https://github.com/rbuckton
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
RescheduledThis issue was previously scheduled to an earlier milestonehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Rescheduled%22
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
https://github.com/borekb
Borek Bernard (borekb)https://github.com/borekb
on Nov 29, 2019https://github.com/microsoft/TypeScript/issues/35420#issue-530272338
CodeSandboxhttps://codesandbox.io/s/inspiring-lewin-eyt6r
es-shims/Promise.allSettled#5https://github.com/es-shims/Promise.allSettled/issues/5
Jordan Harband (@ljharb)https://github.com/ljharb
Babel playgroundhttps://babeljs.io/en/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=JYWwDg9gTgLgBAQwDZIMoFMYyegJnAMyghDgHIxiRgBndAOmSTqx1zIG4AoLgYwgB2NeFHQ0ISAG544AXjgAFKrQajxU9AAoALACYAlN35CR6AFbpeMGfKUkV9URauaAtAEZDPJhlZ5NANpqEtK4ADRwTpbWuAC6-vQwABboAppqAK5IMDRyAHxwAN5ccHDG6gxIEADm6WJZOV4AvoZAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.7.4&externalPlugins=
https://github.com/ljharb
Jordan Harband (ljharb)https://github.com/ljharb
on Nov 29, 2019https://github.com/microsoft/TypeScript/issues/35420#issuecomment-559843363
https://github.com/ajafff
Klaus Meinhardt (ajafff)https://github.com/ajafff
on Dec 27, 2019https://github.com/microsoft/TypeScript/issues/35420#issuecomment-569252209
Jordan Harband (@ljharb)https://github.com/ljharb
https://github.com/ljharb
Jordan Harband (ljharb)https://github.com/ljharb
on Dec 27, 2019https://github.com/microsoft/TypeScript/issues/35420#issuecomment-569313752
Klaus Meinhardt (ajafff)https://github.com/ajafff
on Dec 27, 2019https://github.com/microsoft/TypeScript/issues/35420#event-2911165632
fix receiver of imported and exported functionshttps://github.com/ajafff/TypeScript/commit/ec2ef0b6f080cbc68db60a0551c4ff64e006a32d
https://docs.github.com/articles/closing-issues-via-commit-messages
ec2ef0bhttps://github.com/ajafff/TypeScript/commit/ec2ef0b6f080cbc68db60a0551c4ff64e006a32d
https://github.com/ajafff
Klaus Meinhardt (ajafff)https://github.com/ajafff
on Dec 27, 2019https://github.com/microsoft/TypeScript/issues/35420#issuecomment-569323328
#35877https://github.com/microsoft/TypeScript/pull/35877
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Ron Buckton (rbuckton)https://github.com/rbuckton
on Jan 22, 2020https://github.com/microsoft/TypeScript/issues/35420#event-2971151926
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Jan 22, 2020https://github.com/microsoft/TypeScript/issues/35420#event-2971152107
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.8.1https://github.com/microsoft/TypeScript/milestone/107
on Jan 22, 2020https://github.com/microsoft/TypeScript/issues/35420#event-2971152236
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 3.8.1https://github.com/microsoft/TypeScript/milestone/107
TypeScript 4.0https://github.com/microsoft/TypeScript/milestone/114
on May 1, 2020https://github.com/microsoft/TypeScript/issues/35420#event-3293561781
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.0https://github.com/microsoft/TypeScript/milestone/114
Typescript 4.0.1https://github.com/microsoft/TypeScript/milestone/123
on Jun 29, 2020https://github.com/microsoft/TypeScript/issues/35420#event-3493733779
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
RescheduledThis issue was previously scheduled to an earlier milestonehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Rescheduled%22
on Aug 31, 2020https://github.com/microsoft/TypeScript/issues/35420#event-3710491923
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.0.1https://github.com/microsoft/TypeScript/milestone/123
TypeScript 4.1.0https://github.com/microsoft/TypeScript/milestone/124
on Aug 31, 2020https://github.com/microsoft/TypeScript/issues/35420#event-3710493941
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
TypeScript 4.1.0https://github.com/microsoft/TypeScript/milestone/124
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
on Dec 11, 2020https://github.com/microsoft/TypeScript/issues/35420#event-4101715451
Ron Buckton (rbuckton)https://github.com/rbuckton
on Feb 9, 2021https://github.com/microsoft/TypeScript/issues/35420#event-4307052815
fix receiver of imported and exported functionshttps://github.com/ajafff/TypeScript/commit/2d77419a5d8bbd633931496ac3dcb2566d4f5ce3
https://docs.github.com/articles/closing-issues-via-commit-messages
2d77419https://github.com/ajafff/TypeScript/commit/2d77419a5d8bbd633931496ac3dcb2566d4f5ce3
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
on Feb 9, 2021https://github.com/microsoft/TypeScript/issues/35420#event-4307053114
Ron Buckton (rbuckton)https://github.com/rbuckton
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#35877https://github.com/microsoft/TypeScript/pull/35877
on Mar 3, 2021https://github.com/microsoft/TypeScript/issues/35420#event-4403689901
Ron Buckton (rbuckton)https://github.com/rbuckton
on Mar 3, 2021https://github.com/microsoft/TypeScript/issues/35420#event-4403690420
fix receiver on calls of imported and exported functions (#35877)https://github.com/microsoft/TypeScript/commit/7751ecb544a4e318a4f63fe1e2fb13329d7b5de4
#35877https://github.com/microsoft/TypeScript/pull/35877
https://docs.github.com/articles/closing-issues-via-commit-messages
7751ecbhttps://github.com/microsoft/TypeScript/commit/7751ecb544a4e318a4f63fe1e2fb13329d7b5de4
https://github.com/gdh1995
Dahan Gong (gdh1995)https://github.com/gdh1995
on Jul 4, 2021https://github.com/microsoft/TypeScript/issues/35420#issuecomment-873564686
Ron Buckton (@rbuckton)https://github.com/rbuckton
copybara-servicehttps://github.com/apps/copybara-service
on Sep 10, 2021https://github.com/microsoft/TypeScript/issues/35420#event-5286468246
Avoid marking any indirect function call as useless code.https://github.com/google/closure-compiler/commit/4d5bf4a0bed8e01763f4914bd261fa1f42ee449d
4d5bf4ahttps://github.com/google/closure-compiler/commit/4d5bf4a0bed8e01763f4914bd261fa1f42ee449d
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/35420#event-20416833745
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/35420
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35420
Ron Buckton (rbuckton)https://github.com/rbuckton
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
RescheduledThis issue was previously scheduled to an earlier milestonehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Rescheduled%22
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.