Title: Suggestion: Using typeof with an expression · Issue #4233 · microsoft/TypeScript · GitHub
Open Graph Title: Suggestion: Using typeof with an expression · Issue #4233 · microsoft/TypeScript
X Title: Suggestion: Using typeof with an expression · Issue #4233 · microsoft/TypeScript
Description: It would be helpful if the typeof keyword were changed to support more complex expressions, such as function calls. Example Given the following AngularJS service definition: module myApp { function myApiFactory($http: HttpSvc) { return {...
Open Graph Description: It would be helpful if the typeof keyword were changed to support more complex expressions, such as function calls. Example Given the following AngularJS service definition: module myApp { function...
X Description: It would be helpful if the typeof keyword were changed to support more complex expressions, such as function calls. Example Given the following AngularJS service definition: module myApp { function...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/4233
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Using typeof with an expression","articleBody":"It would be helpful if the `typeof` keyword were changed to support more complex expressions, such as function calls.\n#### Example\n\nGiven the following AngularJS service definition:\n\n``` js\nmodule myApp {\n function myApiFactory($http: HttpSvc) {\n return {\n getSetting: (key: string) => $http.get(etc),\n };\n }\n angular.service(\"myApi\", myApiFactory);\n}\n```\n\nIt would be good if the following statement were possible:\n\n``` js\nexport type MyApi = typeof myApiFactory();\n```\n#### Explanation\n\nSince the function is a factory rather than the actual service, this type alias would other components to have a strongly-typed reference to the service. Though this example relates to AngularJS' service factory and dependency injection, this particular change would not be solely for AngularJS support.\n#### Existing solutions\n\nOne option to resolve this issue is to explicitly define an interface for the service. However, this solution would require repeating the signature for all of the service's methods.\n\nA workaround exists that relies on JavaScript's scoping rules to satisfy TypeScript's `typeof` keyword. However, it significantly reduces readability and clarity. An example:\n\n``` js\nif (false)\n var obj = myApiFactory(null);\nexport type MyApi = typeof obj;\n```\n","author":{"url":"https://github.com/Andael","@type":"Person","name":"Andael"},"datePublished":"2015-08-08T02:20:20Z","url":"https://github.com/microsoft/TypeScript/issues/4233"}
| 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:b86d52ca-e667-114f-60e9-621e65901f3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFD0:2C3566:8514D4:B28274:6B00DD06 |
| html-safe-nonce | f3f5f9492efb3b092492d91b798b7be3b861b71f65240e62672006a39b358392 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkQwOjJDMzU2Njo4NTE0RDQ6QjI4Mjc0OjZCMDBERDA2IiwidmlzaXRvcl9pZCI6IjEyMjEyMjY0ODg3MjkyMzA1OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0f6c8c505e6a4180902e43f8a98c55d1a5118cf97a79b5c8d105e76391033a3d |
| hovercard-subject-tag | issue:99760852 |
| 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/4233/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24e26f518daaf52a8a9a77b1c7b9667625c0ecc4ea28ed05f3210dc29839bf08/microsoft/TypeScript/issues/4233 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24e26f518daaf52a8a9a77b1c7b9667625c0ecc4ea28ed05f3210dc29839bf08/microsoft/TypeScript/issues/4233 |
| og:image:alt | It would be helpful if the typeof keyword were changed to support more complex expressions, such as function calls. Example Given the following AngularJS service definition: module myApp { function... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andael |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width