Title: Re-exporting CJS module with `export =` from ESM via `export *` causes type error · Issue #51923 · microsoft/TypeScript · GitHub
Open Graph Title: Re-exporting CJS module with `export =` from ESM via `export *` causes type error · Issue #51923 · microsoft/TypeScript
X Title: Re-exporting CJS module with `export =` from ESM via `export *` causes type error · Issue #51923 · microsoft/TypeScript
Description: Bug Report TypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with export = via export * in an ES module. 🔎 Search Terms "'export =' and cannot be used with 'export *'" 🕗 Version & Regression ...
Open Graph Description: Bug Report TypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with export = via export * in an ES module. 🔎 Search Terms "'export =' and cannot be used ...
X Description: Bug Report TypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with export = via export * in an ES module. 🔎 Search Terms "'export =' and ca...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/51923
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Re-exporting CJS module with `export =` from ESM via `export *` causes type error","articleBody":"# Bug Report\r\n\r\nTypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with `export =` via `export *` in an ES module.\r\n\r\n### 🔎 Search Terms\r\n\r\n- \"'export =' and cannot be used with 'export *'\"\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n5.0.0-dev.20221216\r\n\r\n### ⏯ Playground Link\r\n\r\nN/A - multiple files\r\n\r\n### 💻 Code\r\n\r\n1. `mkdir scratch && cd scratch`\r\n1. `npm init -y`\r\n1. `npm i react @types/react typescript@next`\r\n1. tsconfig.json\r\n ```json\r\n {\r\n \"compilerOptions\": {\r\n \"target\": \"ESNext\",\r\n \"moduleResolution\": \"NodeNext\",\r\n \"strict\": true\r\n }\r\n }\r\n ```\r\n1. react.mts\r\n ```ts\r\n export * from \"react\";\r\n\r\n // notice this import is fine and does not error\r\n import { useCallback } from \"react\";\r\n ```\r\n1. main.mts\r\n ```ts\r\n import { useCallback } from \"./react.mjs\";\r\n console.log(useCallback);\r\n ```\r\n\r\n### 🙁 Actual behavior\r\n\r\nTry type checking & emitting:\r\n\r\n```\r\n> npx tsc\r\nmain.mts:1:10 - error TS2305: Module '\"./react.mjs\"' has no exported member 'useCallback'.\r\n\r\n1 import { useCallback } from \"./react.mjs\";\r\n ~~~~~~~~~~~\r\n\r\nreact.mts:1:15 - error TS2498: Module '\"V:/scratch-npm/node_modules/@types/react/index\"' uses 'export =' and cannot be used with 'export *'.\r\n\r\n1 export * from \"react\";\r\n ~~~~~~~\r\n\r\n\r\nFound 2 errors in 2 files.\r\n\r\nErrors Files\r\n 1 main.mts:1\r\n 1 react.mts:1\r\n```\r\n\r\nIt will emit, so try running it and see that it works:\r\n\r\n```\r\n> node main.mjs\r\n[Function: useCallback]\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nShould type check fine because this works at runtime and `export =` matches the runtime code which has a single `module .exports = ...` assignment.","author":{"url":"https://github.com/dsherret","@type":"Person","name":"dsherret"},"datePublished":"2022-12-16T18:28:08Z","url":"https://github.com/microsoft/TypeScript/issues/51923"}
| 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:868ba0b6-0cf3-2bcc-2f0e-7e5cbb9ccdc9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E462:2876DA:1F17E7B:288F192:6B0534A0 |
| html-safe-nonce | aba5ccabb5620993399e2e7e1a273d306f76ff812a204868cfb7531e7a007ac7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDYyOjI4NzZEQToxRjE3RTdCOjI4OEYxOTI6NkIwNTM0QTAiLCJ2aXNpdG9yX2lkIjoiMTE3OTg2MTMxMDgwOTM4ODE5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 77cac6be80192afedc32b04e30eaaac7169c4af568a531185c435f8f1dadc933 |
| hovercard-subject-tag | issue:1500679263 |
| 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/51923/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d291834271dfc26002b8ca2a0891c0c5a7e0f9b76afd257d38c9c0934b4933e8/microsoft/TypeScript/issues/51923 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d291834271dfc26002b8ca2a0891c0c5a7e0f9b76afd257d38c9c0934b4933e8/microsoft/TypeScript/issues/51923 |
| og:image:alt | Bug Report TypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with export = via export * in an ES module. 🔎 Search Terms "'export =' and cannot be used ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dsherret |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width