Title: Should preserve unique symbols when re‑assigning `module.exports` · Issue #37403 · microsoft/TypeScript · GitHub
Open Graph Title: Should preserve unique symbols when re‑assigning `module.exports` · Issue #37403 · microsoft/TypeScript
X Title: Should preserve unique symbols when re‑assigning `module.exports` · Issue #37403 · microsoft/TypeScript
Description: TypeScript Version: 3.9.0-dev.20200315 Search Terms: object property preserve unique symbol module.exports preserve unique symbol Code // @target: ES2015 // @module: CommonJS // @allowJs // @checkJs // @noEmit // @filename: index.js cons...
Open Graph Description: TypeScript Version: 3.9.0-dev.20200315 Search Terms: object property preserve unique symbol module.exports preserve unique symbol Code // @target: ES2015 // @module: CommonJS // @allowJs // @checkJ...
X Description: TypeScript Version: 3.9.0-dev.20200315 Search Terms: object property preserve unique symbol module.exports preserve unique symbol Code // @target: ES2015 // @module: CommonJS // @allowJs // @checkJ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37403
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Should preserve unique symbols when re‑assigning `module.exports`","articleBody":"## TypeScript Version:\r\n`3.9.0-dev.20200315`\r\n\r\n## Search Terms:\r\n- object property preserve unique symbol\r\n- module.exports preserve unique symbol\r\n\r\n## Code\r\n```ts repro\r\n// @target: ES2015\r\n// @module: CommonJS\r\n// @allowJs\r\n// @checkJs\r\n// @noEmit\r\n// @filename: index.js\r\nconst customSymbol = Symbol(\"custom\");\r\n// ^?\r\n\r\n// This is a common pattern in Node’s built-in modules:\r\nmodule.exports = {\r\n\tcustomSymbol,\r\n\t// ^?\r\n};\r\n```\r\n\r\n[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?checkJs=true&allowJs=true&target=2&module=1&noEmit=true&allowSyntheticDefaultImports=true#code/PTAEAEBcEMCcHMCmkBcoCiBlATABgIwCsAUCBALYD2AJgK4A2iaAwpeVQHYBSmpY40evUoB3LgGc+EAMYALRNIDWEqeA6V05AJaRVAMy2MO0ck1BaO1RAA8AdACtJ0yh3GRQ02m7aYAnuQAjSnpQAF5QP0DggAoAIk9vcliASgBuKVBMrOysgD0AfmIpABVZLXFzCugPNk5QAAdoSEhEWA5zdoA5GkRATAIKgNpDSABaC1AqOkZxFGJJhkRbG3rKWEgK8IBvYgBIBMgffyD6ABpdshzMguIAX3SgA)\r\n\r\nAlso, the following requires a `// @ts‑ignore` comment, but otherwise works:\r\n\r\n```ts\r\n// some-module.js\r\nconst customSymbol = Symbol(\"custom\");\r\n\r\n// This is a common pattern in Node’s built-in modules:\r\nmodule.exports = {\r\n\t/** @type {typeof customSymbol} */\r\n\t// @ts-ignore\r\n\tcustomSymbol,\r\n// \t~~~~~~~~~~~~ TS2322: Type 'symbol' is not assignable to type 'unique symbol'.\r\n};\r\n```\r\n\r\n## Expected behavior:\r\n```ts\r\n// some-module.d.ts\r\ndeclare const customSymbol: unique symbol;\r\ndeclare const _default: {\r\n\tcustomSymbol: typeof customSymbol;\r\n};\r\nexport = _default;\r\n```\r\n\r\n## Actual behavior:\r\n```ts\r\n// some-module.d.ts\r\ndeclare const _default: {\r\n\tcustomSymbol: symbol;\r\n};\r\nexport = _default;\r\n```\r\n\r\n## Playground Link:\r\nhttps://www.typescriptlang.org/play?module=1#code/MYewdgzgLgBMCu0QFsDKBPZAjEAbGAvDBtngBQBECSyFAlANwCwAUAKYAeADiAE6xEA3qxii4iKChI5cAGlYBfZiyA\r\n\r\n## Related Issues:\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/23263>\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/37404>","author":{"url":"https://github.com/ExE-Boss","@type":"Person","name":"ExE-Boss"},"datePublished":"2020-03-15T13:47:06Z","url":"https://github.com/microsoft/TypeScript/issues/37403"}
| 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:032dae38-7c6a-8a8b-20da-fd4fe228fdc7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C634:16AB79:847AFA:A9D5C3:6B00E992 |
| html-safe-nonce | 3a7844e64fb83abab5d460b3c7fdbf3fb95b66abc1d17218b204c6ff6ce791ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjM0OjE2QUI3OTo4NDdBRkE6QTlENUMzOjZCMDBFOTkyIiwidmlzaXRvcl9pZCI6IjYyMjQ0NzgwODcwNTMxMDk2NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 73885c6d998db76629dc8b5fcfd1922593bd60553861de7e119a120804739d09 |
| hovercard-subject-tag | issue:581681496 |
| 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/37403/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ff774ddfcdd733e243ffb720ae2d6441c527899f754ccb01b7c73c49e80db711/microsoft/TypeScript/issues/37403 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ff774ddfcdd733e243ffb720ae2d6441c527899f754ccb01b7c73c49e80db711/microsoft/TypeScript/issues/37403 |
| og:image:alt | TypeScript Version: 3.9.0-dev.20200315 Search Terms: object property preserve unique symbol module.exports preserve unique symbol Code // @target: ES2015 // @module: CommonJS // @allowJs // @checkJ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ExE-Boss |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width