Title: Why does { foo: T } not satisfy { [key:string]: T }? · Issue #6041 · microsoft/TypeScript · GitHub
Open Graph Title: Why does { foo: T } not satisfy { [key:string]: T }? · Issue #6041 · microsoft/TypeScript
X Title: Why does { foo: T } not satisfy { [key:string]: T }? · Issue #6041 · microsoft/TypeScript
Description: Various libraries I use want to see dictionary "loops" that take some number of key/value pairs and operate on them. E.g.: async.auto
Open Graph Description: Various libraries I use want to see dictionary "loops" that take some number of key/value pairs and operate on them. E.g.: async.auto
X Description: Various libraries I use want to see dictionary "loops" that take some number of key/value pairs and operate on them. E.g.: async.auto<any>({ 'foo': (cb) => getFoo(cb), ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6041
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Why does { foo: T } not satisfy { [key:string]: T }?","articleBody":"Various libraries I use want to see dictionary \"loops\" that take some number of key/value pairs and operate on them. E.g.:\n\n```\nasync.auto\u003cany>({\n 'foo': (cb) => getFoo(cb),\n 'bar': ['foo', (cb, results) => getBar(results.foo)]\n}, (err, results) => { ... });\n```\n\nThe typings file for async likes to [define helper dictionary](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/async/async.d.ts#L6) types like this:\n\n```\ninterface Dictionary\u003cT> { [key: string]: T; }\n```\n\nPeriodically, I need to create these key/value pairs conditionally and on the fly but the compiler yells at me if I try to send it in without explicitly typing my temporary object:\n\n```\nvar block = {\n 'foo': (cb) => getFoo(cb),\n 'bar': ['foo', (cb, results) => getBar(results.foo)\n}\n\nif (flag) {\n block.foo = getOtherFoo(cb);\n}\n\nasync.auto\u003cany>(block, (err, results) => { ... });\n```\n\n`block` now technically satisfies the `{ [key: string]: T; }` because it is an object with two keys, both strings. TypeScript will still yell at me for it, though, unless I explicit add a similar dictionary type to `block`. I, therefore, find myself putting this dictionary type all over the place just to satisfy what seems to be an arbitrary distinction between what is or is not a `key:string`.\n\nThis comes up enough that I find the type bloat irritating and it also makes it a requirement to _only_ access `block.foo` as `block['foo']`.\n","author":{"url":"https://github.com/MrHen","@type":"Person","name":"MrHen"},"datePublished":"2015-12-10T21:15:39Z","url":"https://github.com/microsoft/TypeScript/issues/6041"}
| 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:db81a4a6-b5cf-c3da-b22b-fb84cb75239d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8040:3F8AB1:BCB1B9:F376CF:6B00E9DA |
| html-safe-nonce | fbcfd157fde93911d8b98ca61598ba53c9f8252213733af36830d436414c75a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDQwOjNGOEFCMTpCQ0IxQjk6RjM3NkNGOjZCMDBFOURBIiwidmlzaXRvcl9pZCI6IjEyNjIxMTMyODQ2MDE5OTc3ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d2762f71f5f300cb3d5c5bdf4f7d7e2de5fb4dcdc1727c7f46b1c9d270e8d316 |
| hovercard-subject-tag | issue:121578889 |
| 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/6041/issue_layout |
| twitter:image | https://opengraph.githubassets.com/58a1f424524b8ef324a45b9c8dcacd1e34e71269ee5d4ff293e1727470448094/microsoft/TypeScript/issues/6041 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/58a1f424524b8ef324a45b9c8dcacd1e34e71269ee5d4ff293e1727470448094/microsoft/TypeScript/issues/6041 |
| og:image:alt | Various libraries I use want to see dictionary "loops" that take some number of key/value pairs and operate on them. E.g.: async.auto |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MrHen |
| 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