Title: Type annotation for object with unknown properties but known property types? · Issue #7803 · microsoft/TypeScript · GitHub
Open Graph Title: Type annotation for object with unknown properties but known property types? · Issue #7803 · microsoft/TypeScript
X Title: Type annotation for object with unknown properties but known property types? · Issue #7803 · microsoft/TypeScript
Description: I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type. For example: interface Metadata { key: string, value: any } ...
Open Graph Description: I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type. For example: interfa...
X Description: I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type. For example: int...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7803
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type annotation for object with unknown properties but known property types?","articleBody":"I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type.\n\nFor example:\n\n``` ts\n\ninterface Metadata {\n key: string,\n value: any\n}\n\nvar metadata = {\n someReducer: Metadata ,\n anotherReducer: Metadata , \n // ...\n}\n```\n\nIn this scenario:\n- I don't know the property names or number of properties of `metadata`\n- I do know that `Metadata` is the type of all the properties of `metadata`\n\nNow let's imagine that a function take the metadata object as argument:\n\n``` ts\nfunction doSomething(metadata: any) {\n // ...\n}\n```\n\nI used `any` as the type of the argument metadata but It would be great if I could let developers know that all the properties of this object must be of type `Metadata`.\n\nis there any way to create such type annotation?\n","author":{"url":"https://github.com/remojansen","@type":"Person","name":"remojansen"},"datePublished":"2016-04-04T12:00:18Z","url":"https://github.com/microsoft/TypeScript/issues/7803"}
| 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:a2ea3e19-0b2a-0d5e-ebe2-f7e0aac59e20 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF20:C2718:ABA392:DF5616:6B00E983 |
| html-safe-nonce | 54e16f7944e87eeaca79b99a05db609fe0b7effd5efcbce27c5645fdc536825c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjIwOkMyNzE4OkFCQTM5MjpERjU2MTY6NkIwMEU5ODMiLCJ2aXNpdG9yX2lkIjoiNzExMjY4MDkyMzA0ODUwMzY4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 14dd53c8c38d5659fbd4e9ad69c92cb81cdc1cc42feb21ddba7cee4ce0c57b87 |
| hovercard-subject-tag | issue:145663441 |
| 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/7803/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d88940f3a199b7d4c8b6ac226ae5a3e3f3e3f6ceeecc5bbfcc141ab3fc4514e6/microsoft/TypeScript/issues/7803 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d88940f3a199b7d4c8b6ac226ae5a3e3f3e3f6ceeecc5bbfcc141ab3fc4514e6/microsoft/TypeScript/issues/7803 |
| og:image:alt | I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type. For example: interfa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | remojansen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width