René's URL Explorer Experiment


Title: Proposal: Localized typings for definition files · Issue #4668 · microsoft/TypeScript · GitHub

Open Graph Title: Proposal: Localized typings for definition files · Issue #4668 · microsoft/TypeScript

X Title: Proposal: Localized typings for definition files · Issue #4668 · microsoft/TypeScript

Description: This is another proposal for the issue explained in #2839 and #4665. Problem Ambient external module declarations are global in nature. For example, if the following is contained in a definition file included in the program... declare mo...

Open Graph Description: This is another proposal for the issue explained in #2839 and #4665. Problem Ambient external module declarations are global in nature. For example, if the following is contained in a definition fi...

X Description: This is another proposal for the issue explained in #2839 and #4665. Problem Ambient external module declarations are global in nature. For example, if the following is contained in a definition fi...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/4668

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Localized typings for definition files","articleBody":"This is another proposal for the issue explained in #2839 and #4665.\n# Problem\n\nAmbient external module declarations are global in nature. For example, if the following is contained in a definition file included in the program...\n\n``` typescript\ndeclare module \"myutils\" { }\n```\n\n...then `myutils` can be referenced using an import statement **anywhere** in the entire program.\n\nIn contrast, npm packages can generally only import modules that they have explicitly declared as a dependency or that an ancestor in the dependency graph has declared as a dependency.\n\nThis difference can cause issues when multiple copies of (possibly different versions of) definition files are pulled in for the same package. This proposal will use the following example (from #2839) as a reference.\n- myprogram\n  - mylib\n    - myutils@1.0\n  - myotherlib\n    - myutils@2.0\n# Proposal\n\nTo solve this, I propose an opt-in way for a definition file to declare that all imports/references contained in the definition file are localized only to that definition file. This would essentially allow definition files to define packages without accidentally leaking types to the global namespace, very similar to how an npm package does not make its dependencies directly available to the dependent package.\n## Syntactic changes\n\nThere would need to be a way for a definition file to say that it is opting-in to this feature. For example:\n\n```\n/// \u003creferences localized=\"true\" />\n\ndeclare module \"myLib\" { }\n```\n\nI'm not personally tied to what this looks like. If this proposal takes hold, let the bike-shedding begin.\n## Semantic changes\n\nAny ambient declarations (modules, namespaces, variables, etc) that are _referenced_ by the opting-in definition file are scoped to that file only and not made available to the program at large. This includes anything pulled in either through a `/// \u003creference />` tag or an `import` statement. Ambient declarations actually made in the definition file are, of course, made available to the requesting scope (whatever that may be).\n\n``` typescript\n// myutils.1.0.d.ts\n\ndeclare namespace MyUtils {\n  export interface SomeInterface { }\n}\n\ndeclare module \"myutils\" {\n  export = MyUtils;\n}\n\n// myutils.2.0.d.ts\n\ndeclare module \"myutils\" {\n  export interface RenamedInterface { }\n}\n\n// mylib.d.ts\n\n/// \u003creferences localized=\"true\" />\n/// \u003creference path=\"myutils.1.0.d.ts\" />\n\ndeclare module \"mylib\" {\n  import myutils = require('myutils');\n\n  // if using the proposal in #2839, myutils.SomeInterface would not be available\n  // but works with this proposal\n  export var foo: myutils.SomeInterface;\n}\n\n// myotherlib.d.ts\n\n/// \u003creferences localized=\"true\" />\n/// \u003creference path=\"myutils.2.0.d.ts\" />\n\ndeclare module \"myotherlib\" {\n  import myutils = require('myutils');\n  export var foo: myutils.RenamedInterface;\n}\n\n// myprogram.ts\n\n/// \u003creference path=\"mylib.d.ts\" />\n/// \u003creference path=\"myotherlib.d.ts\" />\n\n// this will error since neither declaration of the \"myutils\" module was\n// made available globally\nimport myutils = require('myutils');\n\n// this will also error since the MyUtils namespace was not made\n// available globally\nvar foo: MyUtils.SomeInterface;\n```\n\nAny ambient declarations (modules, namespaces, variables, etc) from a \"higher level\" are allowed, but will be overridden by any ambient declarations referenced by the definition file. No interface/module/namespace merging will occur.\n\n``` typescript\n// mylib.d.ts\n\n/// \u003creferences localized=\"true\" />\n/// \u003creference path=\"myutils.1.0.d.ts\" />\n\ndeclare module \"mylib\" {\n  import myutils = require('myutils');\n  export var foo: myutils.SomeInterface;\n\n  // this errors since the 1.0 \"myutils\" module overwrites\n  // any inherited module (is not merged)\n  export var bar: myutils.RenamedInterface;\n}\n\n// myotherlib.d.ts\n\n/// \u003creferences localized=\"true\" />\n\ndeclare module \"myotherlib\" {\n  // this still works even though there is no \u003creference /> for\n  // it, inherited from higher level\n  import myutils = require('myutils');\n  export var foo: myutils.RenamedInterface;\n}\n\n// myprogram.ts\n\n/// \u003creference path=\"myutils.2.0.d.ts\" />\n/// \u003creference path=\"mylib.d.ts\" />\n\nimport myutils = require('myutils');\n\n// will error, the 2.0 \"myutils\" module isn't somehow merged with 1.0\nexport var foo: myutils.SomeInterface;\n\n// works\nexport var bar: myutils.RenamedInterface;\n```\n# Other\n- ~~It could be interesting to also allow this for non-definition files, to allow similar functionality for \"Proper external modules\" as defined in #4665~~ Proper external modules _are_ definition files, and I think this proposal should apply to them as well.\n- It could be the case that the \"opt-in\" mechanism is not the right way to do things, and instead it should be based on something like the module resolution mechanism (if using node-style resolution, this functionality kicks in automatically)\n- Somewhat inadvertently, this would fix `__MyLib` being available globally in #4337\n","author":{"url":"https://github.com/jbrantly","@type":"Person","name":"jbrantly"},"datePublished":"2015-09-06T00:47:56Z","url":"https://github.com/microsoft/TypeScript/issues/4668"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d0e5a9dc-966f-8f79-8c1c-a6431666bb88
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idABD6:229B2E:DC4917:123E704:6B00FB7A
html-safe-nonce01a64e09c08a3558a66590869c758afd3c56bc15c9609647c08730cda183734d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkQ2OjIyOUIyRTpEQzQ5MTc6MTIzRTcwNDo2QjAwRkI3QSIsInZpc2l0b3JfaWQiOiI1ODYzODU0NzQwMDQ3MTk5MDk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac337f2beb0b274a21c5374f1443e776a0250a327bb318dbc18a77b62b7a9f2c75
hovercard-subject-tagissue:105059572
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/4668/issue_layout
twitter:imagehttps://opengraph.githubassets.com/354f0a593e3b1b53ca5dac92d83f63a2788b9c54281f5b8c8fcac0c0878fb780/microsoft/TypeScript/issues/4668
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/354f0a593e3b1b53ca5dac92d83f63a2788b9c54281f5b8c8fcac0c0878fb780/microsoft/TypeScript/issues/4668
og:image:altThis is another proposal for the issue explained in #2839 and #4665. Problem Ambient external module declarations are global in nature. For example, if the following is contained in a definition fi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejbrantly
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/4668#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F4668
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F4668
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/4668
Reloadhttps://github.com/microsoft/TypeScript/issues/4668
Reloadhttps://github.com/microsoft/TypeScript/issues/4668
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests309 (309)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4668
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4668
Proposal: Localized typings for definition fileshttps://github.com/microsoft/TypeScript/issues/4668#top
https://github.com/RyanCavanaugh
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22%40types%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/jbrantly
James Brantly (jbrantly)https://github.com/jbrantly
on Sep 6, 2015https://github.com/microsoft/TypeScript/issues/4668#issue-105059572
#2839https://github.com/microsoft/TypeScript/issues/2839
#4665https://github.com/microsoft/TypeScript/issues/4665
#2839https://github.com/microsoft/TypeScript/issues/2839
Resolving dependency conflicts when importing node package typings #4665https://github.com/microsoft/TypeScript/issues/4665
Guidance on writing declaration file for multi-targeted libraries #4337https://github.com/microsoft/TypeScript/issues/4337
https://github.com/jbrantly
James Brantly (jbrantly)https://github.com/jbrantly
on Sep 7, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138332264
Wesley Wigham (@weswigham)https://github.com/weswigham
Martin Poelstra (@poelstra)https://github.com/poelstra
https://github.com/poelstra
Martin Poelstra (poelstra)https://github.com/poelstra
on Sep 7, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138339625
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
#4673https://github.com/microsoft/TypeScript/issues/4673
https://github.com/jbrantly
James Brantly (jbrantly)https://github.com/jbrantly
on Sep 7, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138342528
Martin Poelstra (@poelstra)https://github.com/poelstra
#4337https://github.com/microsoft/TypeScript/issues/4337
#4337https://github.com/microsoft/TypeScript/issues/4337
#4673https://github.com/microsoft/TypeScript/issues/4673
#4337https://github.com/microsoft/TypeScript/issues/4337
https://github.com/poelstra
Martin Poelstra (poelstra)https://github.com/poelstra
on Sep 7, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138376581
#4337https://github.com/microsoft/TypeScript/issues/4337
https://github.com/jbrantly
James Brantly (jbrantly)https://github.com/jbrantly
on Sep 7, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138382929
https://github.com/poelstra
Martin Poelstra (poelstra)https://github.com/poelstra
on Sep 8, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138477234
#4665 (comment)https://github.com/microsoft/TypeScript/issues/4665#issuecomment-138370373
https://github.com/jbrantly
James Brantly (jbrantly)https://github.com/jbrantly
on Sep 8, 2015https://github.com/microsoft/TypeScript/issues/4668#issuecomment-138547423
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Sep 9, 2015https://github.com/microsoft/TypeScript/issues/4668#event-404292194
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Dec 10, 2015https://github.com/microsoft/TypeScript/issues/4668#event-487716011
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22%40types%22
on Feb 22, 2016https://github.com/microsoft/TypeScript/issues/4668#event-560411448
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Feb 22, 2016https://github.com/microsoft/TypeScript/issues/4668#event-560411514
https://github.com/tomwanzek
Tom Wanzek (tomwanzek)https://github.com/tomwanzek
on Jul 2, 2016https://github.com/microsoft/TypeScript/issues/4668#issuecomment-230075490
my issue involving local module augmentationhttps://github.com/tomwanzek/d3-v4-definitelytyped/issues/4
typingshttps://github.com/typings/typings
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 4, 2016https://github.com/microsoft/TypeScript/issues/4668#issuecomment-230184094
https://github.com/tomwanzek
Tom Wanzek (tomwanzek)https://github.com/tomwanzek
on Jul 4, 2016https://github.com/microsoft/TypeScript/issues/4668#issuecomment-230330724
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 21, 2016https://github.com/microsoft/TypeScript/issues/4668#issuecomment-234416764
#4673 (comment)https://github.com/microsoft/TypeScript/issues/4673#issuecomment-234416673
https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Introduction.mdhttps://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Introduction.md
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 21, 2016https://github.com/microsoft/TypeScript/issues/4668#event-731139851
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/4668#event-1689614118
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/4668
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4668
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22%40types%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.