Title: Global type references · Issue #983 · microsoft/TypeScript · GitHub
Open Graph Title: Global type references · Issue #983 · microsoft/TypeScript
X Title: Global type references · Issue #983 · microsoft/TypeScript
Description: When a type declaration in an inner module has the same name as a type declaration in an outer module, the outer declaration becomes inaccessible. Programmers can typically work around this, for example by deriving a type with an alterna...
Open Graph Description: When a type declaration in an inner module has the same name as a type declaration in an outer module, the outer declaration becomes inaccessible. Programmers can typically work around this, for ex...
X Description: When a type declaration in an inner module has the same name as a type declaration in an outer module, the outer declaration becomes inaccessible. Programmers can typically work around this, for ex...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/983
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Global type references","articleBody":"When a type declaration in an inner module has the same name as a type declaration in an outer module, the outer declaration becomes inaccessible. Programmers can typically work around this, for example by deriving a type with an alternate name in the outer module or, with our latest changes, by declaring a type alias. However, such manual work-arounds are not a good option for code generation tools such as the .d.ts generation facility provided by the compiler. We really need a fool proof way to ensure a lookup starts at the global scope. Consider:\n\n``` typescript\nfunction makeError(): Error {\n return new Error(\"We've got a problem\");\n}\n\nmodule M {\n export class Error {\n }\n export var x = makeError(); // No way to name global Error type here\n}\n```\n\nIt is currently impossible to create a .d.ts file for the code above because there is no way to emit a type annotation for `x` that references the global interface `Error`.\n\nNode.js uses the name `global` for the global scope. We could consider supporting something similar in type names. Specifically, if a qualified type name starts with the identifier `global` and if a lookup of `global` as a module name doesn't bind to anything (meaning the user didn't define a `global` module), then we consider it a globally qualified name. For the example above we could then generate the following .d.ts file:\n\n``` typescript\ndeclare module M {\n class Error {\n }\n var x: global.Error;\n}\n```\n\nIf course, if the user defines their own `global` module we now have a problem again--but I think it is fine to just say you shouldn't do that. We could even consider making it an error, or allowing it only under a compiler switch.\n","author":{"url":"https://github.com/ahejlsberg","@type":"Person","name":"ahejlsberg"},"datePublished":"2014-10-28T23:29:55Z","url":"https://github.com/microsoft/TypeScript/issues/983"}
| 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:d8225af9-88e2-1581-f531-b474074c6535 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97FA:2BE220:D066DB:1175EC5:6B00FFC6 |
| html-safe-nonce | 4d32f898f46780d0f3f5d5493402aa10178d54241e9643e871898d083519a83f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0ZBOjJCRTIyMDpEMDY2REI6MTE3NUVDNTo2QjAwRkZDNiIsInZpc2l0b3JfaWQiOiI4OTMxMjk2NTU4NjY2ODA5Mjg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7dbb133dda3beb5fbc54ec7df3b6cf6059c54f8e4d5d5e0eeeda65fe5350df76 |
| hovercard-subject-tag | issue:47094780 |
| 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/983/issue_layout |
| twitter:image | https://opengraph.githubassets.com/662ad28d992f4937fb2438bb6e103fe1883865b5e9b7503a55e75934d3086d5d/microsoft/TypeScript/issues/983 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/662ad28d992f4937fb2438bb6e103fe1883865b5e9b7503a55e75934d3086d5d/microsoft/TypeScript/issues/983 |
| og:image:alt | When a type declaration in an inner module has the same name as a type declaration in an outer module, the outer declaration becomes inaccessible. Programmers can typically work around this, for ex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ahejlsberg |
| 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