Title: Suggestion: Permit an implementing class to ignore private methods of the implementee class · Issue #471 · microsoft/TypeScript · GitHub
Open Graph Title: Suggestion: Permit an implementing class to ignore private methods of the implementee class · Issue #471 · microsoft/TypeScript
X Title: Suggestion: Permit an implementing class to ignore private methods of the implementee class · Issue #471 · microsoft/TypeScript
Description: Hi, we have a requirement to create mocks of real classes defined in code. The exact requirements are A specific mock should define the public API of the real class. If the public API of the real class changes in any way then the compile...
Open Graph Description: Hi, we have a requirement to create mocks of real classes defined in code. The exact requirements are A specific mock should define the public API of the real class. If the public API of the real c...
X Description: Hi, we have a requirement to create mocks of real classes defined in code. The exact requirements are A specific mock should define the public API of the real class. If the public API of the real c...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/471
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Permit an implementing class to ignore private methods of the implementee class","articleBody":"Hi, we have a requirement to create mocks of real classes defined in code. The exact requirements are\n- A specific mock should define the public API of the real class.\n- If the public API of the real class changes in any way then the compiler should detect the corresponding breakage in the mock class.\n\nA possible solution might be as follows: \n\n``` TypeScript\ndeclare var fileWriter: any; \n\n// Real class\nclass Foo {\n\n public writeToFile(){\n fileWriter.writeToFile('');\n }\n}\n\n// Mock\nclass MockFoo implements Foo {\n\n public writeToFile(){\n // do nothing\n }\n}\n```\n\nThis appears to solve the problem because changing `Foo.writeToFile` will trigger a compilation error along the lines of \"Class MockFoo declares interface Foo but does not implement it...\"\n\nThe problem with this approach is that `class Foo` is not permitted to have any private methods or fields. If we were to add a private method `foo()` to `class Foo` then it's no longer possible for `MockFoo` to implement `Foo` because the compiler doesn't permit it.\n\nI suggest that when a class implements another class the implementing class be allowed to ignore the private fields and methods (both static and instance) of the implementee.\n\n(I am aware that there are workarounds, such as declaring an interface that both `Foo` and `MockFoo` implement, but that introduces an unnecessary maintenance overhead.)\n","author":{"url":"https://github.com/NoelAbrahams","@type":"Person","name":"NoelAbrahams"},"datePublished":"2014-08-18T12:41:03Z","url":"https://github.com/microsoft/TypeScript/issues/471"}
| 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:7a268300-7192-579b-1a9b-899bd23fa43d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8F2:24FC21:A26A4E:D2E89B:6B00E387 |
| html-safe-nonce | 4fdc37432bd18445de73b2478eb9be7a1808b44794021ce51fef3d2106cbf3f0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEYyOjI0RkMyMTpBMjZBNEU6RDJFODlCOjZCMDBFMzg3IiwidmlzaXRvcl9pZCI6IjE3NzAzNzI4NjM5Mzc3OTkwNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 10a40b2a5661b39d7848c7af5efd4884821b25aee2dc2ef69ce2c4e4325cde63 |
| hovercard-subject-tag | issue:40483812 |
| 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/471/issue_layout |
| twitter:image | https://opengraph.githubassets.com/525127ef55ef845b9f837e57df0900d671fe7d4149aadebf9d387c7eb4f2d214/microsoft/TypeScript/issues/471 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/525127ef55ef845b9f837e57df0900d671fe7d4149aadebf9d387c7eb4f2d214/microsoft/TypeScript/issues/471 |
| og:image:alt | Hi, we have a requirement to create mocks of real classes defined in code. The exact requirements are A specific mock should define the public API of the real class. If the public API of the real c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NoelAbrahams |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width