Title: Proposal: The internal modifier for classes · Issue #5228 · microsoft/TypeScript · GitHub
Open Graph Title: Proposal: The internal modifier for classes · Issue #5228 · microsoft/TypeScript
X Title: Proposal: The internal modifier for classes · Issue #5228 · microsoft/TypeScript
Description: The internal modifier Often there is a need to share information on types within a program or package that should not be accessed from outside of the program or package. While the public accessibility modifier allows types to share infor...
Open Graph Description: The internal modifier Often there is a need to share information on types within a program or package that should not be accessed from outside of the program or package. While the public accessibil...
X Description: The internal modifier Often there is a need to share information on types within a program or package that should not be accessed from outside of the program or package. While the public accessibil...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5228
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: The internal modifier for classes","articleBody":"# The `internal` modifier\n\nOften there is a need to share information on types within a program or package that should not be\naccessed from outside of the program or package. While the `public` accessibility modifier allows\ntypes to share information, is insufficient for this case as consumers of the package have access\nto the information. While the `private` accessibility modifier prevents consumers of the package\nfrom accessing information from the type, it is insufficient for this case as types within the\npackage also cannot access the information. To satisfy this case, we propose the addition of the\n`internal` modifier to class members.\n## Goals\n\nThis proposal aims to describe the static semantics of the `internal` modifier as it applies to members of a class (methods, accessors, and properties).\n## Non-goals\n\nThis proposal does not cover any other use of the `internal` modifier on other declarations.\n# Static Semantics\n## Visibility\n\nWithin a _non-declaration_ file, a class member marked `internal` is treated as if it had `public`\nvisibility for any property access:\n\n**source.ts**:\n\n``` ts\nclass C {\n internal x: number;\n}\n\nlet c = new C();\nc.x = 1; // ok\n```\n\nWhen consuming a class from a _declaration_ file, a class member marked `internal` is treated as\nif it had `private` visibility for any property access:\n\n**declaration.d.ts**\n\n``` ts\nclass C {\n internal x: number;\n}\n```\n\n**source.ts**\n\n``` ts\n/// \u003creference path=\"declaration.d.ts\" />\nlet c = new C();\nc.x = 1; // error\n```\n## Assignability\n\nWhen checking assignability of types within a _non-declaration_ file, a class member marked\n`internal` is treated as if it had `public` visibility:\n\n**source.ts**:\n\n``` ts\nclass C {\n internal x: number;\n}\n\ninterface X {\n x: number;\n}\n\nlet x: X = new C(); // ok\n```\n\nIf one of the types is imported or referenced from a _declaration_ file, but the other is defined\ninside of a _non-declaration_ file, a class member marked `internal` is treated as if it had\n`private` visibility:\n\n**declaration.d.ts**\n\n``` ts\nclass C {\n internal x: number;\n}\n```\n\n**source.ts**\n\n``` ts\n/// \u003creference path=\"declaration.d.ts\" />\ninterface X {\n}\n\nlet x: X = new C(); // error\n```\n\nIt is important to allow assignability between super- and subclasses from a declaration file\nwith overridden members marked `internal`. When both types are imported or referenced from a\n_declaration_ file, a class member marked `internal` is treated as if it had `protected` visibility:\n\n**declaration.d.ts**\n\n``` ts\nclass C {\n internal x(): void;\n}\n\nclass D extends C {\n internal x(): void;\n}\n```\n\n**source.ts**\n\n``` ts\n/// \u003creference path=\"declaration.d.ts\" />\nlet c: C = new D(); // ok\n```\n\nHowever, this does not carry over to subclasses that are defined in a _non-declaration_ file:\n\n**declaration.d.ts**\n\n``` ts\nclass C {\n internal x(): void;\n}\n```\n\n**source.ts**\n\n``` ts\n/// \u003creference path=\"declaration.d.ts\" />\nclass D extends C {\n internal x(): void; // error\n}\n```\n","author":{"url":"https://github.com/rbuckton","@type":"Person","name":"rbuckton"},"datePublished":"2015-10-12T18:27:12Z","url":"https://github.com/microsoft/TypeScript/issues/5228"}
| 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:f505ebdd-b865-a553-8928-849355c57ab5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACD4:38C5CF:3FA577:541020:6B00C628 |
| html-safe-nonce | b151e48ed419d1a3a08459f5336bbcb73b8d1f2a7683b8828f9f6f74121aaaf6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0Q0OjM4QzVDRjozRkE1Nzc6NTQxMDIwOjZCMDBDNjI4IiwidmlzaXRvcl9pZCI6IjYzODg0NTk3MzIyNTU5NTAzNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c48401cc2bcec75a1ce2b5c25c2fc55ecac5e7f923a84d7c06a01bff8e57e1d4 |
| hovercard-subject-tag | issue:111028950 |
| 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/5228/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7269b145ff5003e5a0edb32919d67e1df377626853aaf986db3ea8e6a149f149/microsoft/TypeScript/issues/5228 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7269b145ff5003e5a0edb32919d67e1df377626853aaf986db3ea8e6a149f149/microsoft/TypeScript/issues/5228 |
| og:image:alt | The internal modifier Often there is a need to share information on types within a program or package that should not be accessed from outside of the program or package. While the public accessibil... |
| 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 | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width