Title: Consider allowing packages to define multiple canonical names for their modules · Issue #42764 · microsoft/TypeScript · GitHub
Open Graph Title: Consider allowing packages to define multiple canonical names for their modules · Issue #42764 · microsoft/TypeScript
X Title: Consider allowing packages to define multiple canonical names for their modules · Issue #42764 · microsoft/TypeScript
Description: Suggestion This is based on a change in the NodeJS definitions: DefinitelyTyped/DefinitelyTyped#51107. For Node's ESM support, you can import NodeJS core packages (i.e., fs, path, etc.) using a fully-qualified URN with the node: prefix. ...
Open Graph Description: Suggestion This is based on a change in the NodeJS definitions: DefinitelyTyped/DefinitelyTyped#51107. For Node's ESM support, you can import NodeJS core packages (i.e., fs, path, etc.) using a ful...
X Description: Suggestion This is based on a change in the NodeJS definitions: DefinitelyTyped/DefinitelyTyped#51107. For Node's ESM support, you can import NodeJS core packages (i.e., fs, path, etc.) using a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/42764
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider allowing packages to define multiple canonical names for their modules","articleBody":"# Suggestion\r\n\r\nThis is based on a change in the NodeJS definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51107. For Node's ESM support, you can import NodeJS core packages (i.e., `fs`, `path`, etc.) using a fully-qualified URN with the `node:` prefix. The approach taken in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51107 is to re-export a module like `fs` using another ambient module:\r\n\r\n```ts\r\ndeclare module \"node:fs\" {\r\n export * from \"fs\";\r\n}\r\ndeclare module \"fs\" {\r\n ...\r\n}\r\n```\r\n\r\nHowever, this belies the actual behavior of the import. `\"node:fs\"` is not a *different* module that happens to re-export `\"fs\"`, it is actually the *same* module, and ideally would be handled in a way similar to how we currently handle symbolic links. With the above definitions, any module augmentations must always be made against the non-prefixed form of the module. Augmentations of the prefixed-form would be missing when importing the non-prefixed form.\r\n\r\nWe already have some mechanisms for handling this in your *own* project (i.e., via `\"paths\"`, etc.), but not when importing from an external package (such as is the case with `\"fs\"`, `\"path\"`, etc.).\r\n\r\nShould we consider adding a mechanism, be it either via syntax or via configuration (stored in `package.json`)?\r\n\r\n### Syntax\r\nWe can bikeshed on syntax, but I've presented a few options below:\r\n\r\n```ts\r\n// 1) variation of `export as namespace ...`\r\ndeclare module \"fs\" {\r\n export as module \"node:fs\"; // essentially a symbolic link from `\"node:fs\"` to `\"fs\"`\r\n}\r\n\r\n// 2) declare a module with multiple names\r\ndeclare module \"fs\", \"node:fs\" {\r\n}\r\n```\r\n\r\n### Configuration\r\nIf we consider approaching this problem from a configuration standpoint there are a number of directions we could take. I can update this section as we discuss this issue.\r\n\r\n## 🔍 Search Terms\r\n\r\nNodeJS, ESM, prefix, symlink\r\n\r\n","author":{"url":"https://github.com/rbuckton","@type":"Person","name":"rbuckton"},"datePublished":"2021-02-11T20:02:34Z","url":"https://github.com/microsoft/TypeScript/issues/42764"}
| 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:6c912583-1f23-cb7c-94f0-36c1a3138460 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8478:161320:D41F73:119835C:6B01CD35 |
| html-safe-nonce | c6eb0ebbeeeadba3301e6499fdf0292af646d186c88984891bbe6ebd1f5a8edf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDc4OjE2MTMyMDpENDFGNzM6MTE5ODM1Qzo2QjAxQ0QzNSIsInZpc2l0b3JfaWQiOiI2Mjk1NTUzNDE3Nzc1NTMzMzY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 21b47d0da8de022d17ebfeb47917d9e30bcb3681974e8568b6ff692e7ba39c26 |
| hovercard-subject-tag | issue:806699126 |
| 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/42764/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ae19a297ae196400b5652f8bbb47a60361a9f8ddbc192427d3aba41b2a13b3e6/microsoft/TypeScript/issues/42764 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ae19a297ae196400b5652f8bbb47a60361a9f8ddbc192427d3aba41b2a13b3e6/microsoft/TypeScript/issues/42764 |
| og:image:alt | Suggestion This is based on a change in the NodeJS definitions: DefinitelyTyped/DefinitelyTyped#51107. For Node's ESM support, you can import NodeJS core packages (i.e., fs, path, etc.) using a ful... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rbuckton |
| 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