Title: Resolving dependency conflicts when importing node package typings · Issue #4665 · microsoft/TypeScript · GitHub
Open Graph Title: Resolving dependency conflicts when importing node package typings · Issue #4665 · microsoft/TypeScript
X Title: Resolving dependency conflicts when importing node package typings · Issue #4665 · microsoft/TypeScript
Description: This issue is explained in details in #2839 Terminology Through out this issue, i will be referring to different ways of declaring external modules, here are what i mean by them. Ambient external module declaration Module declarations of...
Open Graph Description: This issue is explained in details in #2839 Terminology Through out this issue, i will be referring to different ways of declaring external modules, here are what i mean by them. Ambient external m...
X Description: This issue is explained in details in #2839 Terminology Through out this issue, i will be referring to different ways of declaring external modules, here are what i mean by them. Ambient external m...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4665
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Resolving dependency conflicts when importing node package typings","articleBody":"This issue is explained in details in https://github.com/Microsoft/TypeScript/issues/2839\n## Terminology\n\nThrough out this issue, i will be referring to different ways of declaring external modules, here are what i mean by them.\n#### Ambient external module declaration\n\nModule declarations of the form:\n\n``` ts\ndeclare module \"mod\" {\n ....\n}\n```\n#### Proper external modules\n\nThe other way of writing a declaration of a module, i.e. a declaration file with a top level `import` or `export`; e.g.:\n\n``` ts\nimport { Contract } from \".\\core\"\nexport var MyContract: Contract;\n```\n#### Script file\n\nA file that is not a module, i.e. does not include a top level `import` or `export`. it could however, include ambient external module declarations as described above.\n## Background\n\nWith module resolution work done in #4154 and #4352, it is possible for node package authors to distribute typings with their packages. For these packages, users do not have to independently acquire the typings from definitely typed, but will just `import` the package, the the compiler will locate the typings in the package directory (either `index.d.ts` or by following `typings` property in `package.json` in the package directory).\n\nAs noted in #2839, for a package author interested in distributing their typings with their package, there are dependencies that they need typings for; the most common would be `node.d.ts`, which is possibly referenced by each package.\n\nThe way they dependency typing are authored today on definitely typed is using _ambient external module declaration_; this indicates that these typings exist in the global scope, and thus are susceptible to conflicts. The classic the diamond dependency issue (courtesy of @poelstra):\n- myprogram\n - mylib\n - myutils@1.0\n - myotherlib\n - myutils@2.0\n\nNow, if `myUtils.d.ts` uses _ambient external module declaration_, this is guaranteed to result in re-declaration errors.\n## Proposal\n\nWhen resolving an `import` target in a node module, it is an **error** to include files that are **not** either:\n1. **Proper external modules**, or\n2. A **Versioned script file** - see below\n\nFor proper external modules, there are no conflicts expected, as external modules do no polute the global namespace.\n\nFor versioned files, referring to the same library, the compiler will follow a _conflict resolution_ logic picking only the **latest** copy (as described by @basarat in https://github.com/Microsoft/TypeScript/issues/2839#issuecomment-94630741). The files provided on the command line will be allowed to override this conflict resolution policy.\n## Versioned files\n\nThese are files declaring an **identity**, i.e. a name and a version. A versioned file is expected to contain a comment at the top of the form\n\n``` ts\n/// \u003clibrary name=\"myLibraryName\" version=\"1.0.23.2-beta\" />\n```\n\nWhere the `name` field is optional, and if committed, the file name is used instead, and the `version` field follows the version definition in http://semver.org/\n","author":{"url":"https://github.com/mhegazy","@type":"Person","name":"mhegazy"},"datePublished":"2015-09-05T20:22:33Z","url":"https://github.com/microsoft/TypeScript/issues/4665"}
| 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:1d2de555-0ffa-01bc-0ab8-305bf0280f8b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A15A:21BD98:FFB42:1414B7:6B00F7D7 |
| html-safe-nonce | fbfcf7df6c233c8d9b7b51e5f3d60d68558c88998eed5ccae2f6f7a76f85bcd9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTVBOjIxQkQ5ODpGRkI0MjoxNDE0Qjc6NkIwMEY3RDciLCJ2aXNpdG9yX2lkIjoiNDE0MTg2MTg2MjcwMDU0NjAwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4f5a9b4b1e667d336ec43c55cba293f61a3685ed9a30cfc9b50cced2d9d33da9 |
| hovercard-subject-tag | issue:105047101 |
| 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/4665/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fc0f0de635422705090988d72479ba802c49193c4e7d673be93ae4429ce62c7b/microsoft/TypeScript/issues/4665 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fc0f0de635422705090988d72479ba802c49193c4e7d673be93ae4429ce62c7b/microsoft/TypeScript/issues/4665 |
| og:image:alt | This issue is explained in details in #2839 Terminology Through out this issue, i will be referring to different ways of declaring external modules, here are what i mean by them. Ambient external m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhegazy |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width