Title: Question: Desired behavior of triple-slash references in commonjs modules · Issue #4694 · microsoft/TypeScript · GitHub
Open Graph Title: Question: Desired behavior of triple-slash references in commonjs modules · Issue #4694 · microsoft/TypeScript
X Title: Question: Desired behavior of triple-slash references in commonjs modules · Issue #4694 · microsoft/TypeScript
Description: Here's an example demonstrating what I'm about to ask about. As of the TS 1.6 beta, we've started following package references for typings! Cool! This lets us use patterns more familiar to commonjs package consumers to distribute types, ...
Open Graph Description: Here's an example demonstrating what I'm about to ask about. As of the TS 1.6 beta, we've started following package references for typings! Cool! This lets us use patterns more familiar to commonjs...
X Description: Here's an example demonstrating what I'm about to ask about. As of the TS 1.6 beta, we've started following package references for typings! Cool! This lets us use patterns more familiar...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4694
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Question: Desired behavior of triple-slash references in commonjs modules","articleBody":"[Here's an example](https://github.com/weswigham/typed-node) demonstrating what I'm about to ask about.\n\nAs of the TS 1.6 beta, we've started following package references for typings! Cool! This lets us use patterns more familiar to commonjs package consumers to distribute types, which is awesome! There's in interesting issue, though. I'm ignoring the global ambient module scoping problem - let's say I plan to use proper external modules all the time.\n\nWhen this is the case, if I _do_ want to pollute the global scope, it is impossible for me to do so _within the typings file found by TS_. (Since it's an external module, all its types are internal except those exported.) However, by `/// ref`'ing a file which globally pollutes, I can presently globally pollute. Given that external modules aren't supposed to leak types, this is... awkward. This is a result of how loosely we add `///ref`'d files versus those found via module resolution. While it works as a global scope pollution workaround at present, I think this behavior is something we should change/scope/specify _before_ the full release of TS 1.6, or it could result in some bad behavior in these cases.\n\nInterestingly, these globals don't get injected into the global scope until you add\n\n``` ts\nimport \"typed-node\";\n```\n\nwhich looks up the module (and injects the ref in the found module). Honestly, in an external module `.d.ts`, I'm not sure the behavior of this statement was ever really specced, which is why I'm bringing it up. The compiler would _never emit this statement itself_ into a `.d.ts` from what I can tell, yet we do interesting things when we read it in one.\n\nI have no issue with this statement in a `.d.ts`. Actually, I think this is quite nice from the perspective of how it gets used, using the import-for-side-effects to just pull in globals (AKA typesystem side effects) actually feels right. Here's the problem, though - when the module I've written that `import` in gets `import`ed (in any way), now the containing package has that ref file and its types in its scope, too.\n\nThis means that `import * as http from \"typed-http\"` inadvertently adds `Buffer` to the global scope! `Buffer`'s not even defined in that module! It's in a different package entirely! And `typed-http` _never explicitly exported it_, despite being a proper external module!\n\nWhat I'd like to see is that \"global\" Buffer available in packages which have _explicitly_ done `import \"typed-node\"`. In effect, importing a package for side effects could merge its globals into yours (but not the other way around), and those globals are _never_ leaked into a containing package otherwise. If this were the case, then different packages could rely on different versions of \"typed-node\" without fear. (Without polluting the environment of those who only access their explicit exports!)\n","author":{"url":"https://github.com/weswigham","@type":"Person","name":"weswigham"},"datePublished":"2015-09-08T19:08:50Z","url":"https://github.com/microsoft/TypeScript/issues/4694"}
| 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:6625d373-59c8-e0bf-8caf-26e040697b08 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5AC:95C88:EAD011:13771F5:6B0101C6 |
| html-safe-nonce | 61befc8bfe8cfdab1f4dbe26c20d0622040c825e1986aa312b6541ab8986a9c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUFDOjk1Qzg4OkVBRDAxMToxMzc3MUY1OjZCMDEwMUM2IiwidmlzaXRvcl9pZCI6IjYxMzM3NjQwOTU2NzkyMDE3MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0001cc67a50ebc7fa04395add0d4e6bee47a77a2eaa072aa35c57eaf618cc92a |
| hovercard-subject-tag | issue:105450018 |
| 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/4694/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d45f165aa8c0fb395cfb1cc4c144f9b4ed7c23c8e9e3ee38439275bb2b06ec6/microsoft/TypeScript/issues/4694 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d45f165aa8c0fb395cfb1cc4c144f9b4ed7c23c8e9e3ee38439275bb2b06ec6/microsoft/TypeScript/issues/4694 |
| og:image:alt | Here's an example demonstrating what I'm about to ask about. As of the TS 1.6 beta, we've started following package references for typings! Cool! This lets us use patterns more familiar to commonjs... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | weswigham |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width