Title: index operator and object spread · Issue #17849 · microsoft/TypeScript · GitHub
Open Graph Title: index operator and object spread · Issue #17849 · microsoft/TypeScript
X Title: index operator and object spread · Issue #17849 · microsoft/TypeScript
Description: TypeScript Version: 2.4.2 Code interface HasIndex { [key : string] : number } interface HasPropWithHasIndex { hasIndex ?: HasIndex } // one - works fine const obj1 : HasPropWithHasIndex = { hasIndex: { a: 1 } } // two - works fine const ...
Open Graph Description: TypeScript Version: 2.4.2 Code interface HasIndex { [key : string] : number } interface HasPropWithHasIndex { hasIndex ?: HasIndex } // one - works fine const obj1 : HasPropWithHasIndex = { hasInde...
X Description: TypeScript Version: 2.4.2 Code interface HasIndex { [key : string] : number } interface HasPropWithHasIndex { hasIndex ?: HasIndex } // one - works fine const obj1 : HasPropWithHasIndex = { hasInde...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/17849
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"index operator and object spread","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:** 2.4.2\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface HasIndex {\r\n [key : string] : number\r\n}\r\ninterface HasPropWithHasIndex {\r\n hasIndex ?: HasIndex\r\n}\r\n\r\n// one - works fine\r\nconst obj1 : HasPropWithHasIndex = {\r\n hasIndex: {\r\n a: 1\r\n }\r\n}\r\n\r\n// two - works fine\r\nconst test2 = { a: 1 }\r\nconst obj2 : HasPropWithHasIndex = {\r\n hasIndex: test2\r\n}\r\n\r\n// three - doesn't work\r\nconst obj = {\r\n a: 1,\r\n b: 2,\r\n c: 3,\r\n}\r\nconst { a, ...test3 } = obj\r\n// Error: Index signature is missing in type '{ b: number; c: number; }'.\r\nconst obj3 : HasPropWithHasIndex = {\r\n hasIndex: test3,\r\n}\r\n\r\n// four - test4 should be of type number, is instead of type any\r\nconst test4 = test3['a']\r\n```\r\n\r\n**Expected behavior:**\r\nThe `obj3` assignment in test three should work without an issue.\r\n`test4` in test four should be of type `number`\r\n\r\n**Actual behavior:**\r\nThe `obj3` assignment in test three throws an error: `Index signature is missing in type '{ b: number; c: number; }'.`\r\n`test4` is of type `any`.\r\n\r\nIt looks like when you use the spread operator, typescript changes the type of the index operator to return `any`.","author":{"url":"https://github.com/bradzacher","@type":"Person","name":"bradzacher"},"datePublished":"2017-08-16T23:25:25Z","url":"https://github.com/microsoft/TypeScript/issues/17849"}
| 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:237b488d-6618-3176-e1d8-a8aaf28585b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC46:269AD9:9B161C:D12AD1:6B00EA4C |
| html-safe-nonce | e831613f39a94211d357229747588e555b895e487fab44530d53e974e8aca264 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzQ2OjI2OUFEOTo5QjE2MUM6RDEyQUQxOjZCMDBFQTRDIiwidmlzaXRvcl9pZCI6IjU5ODQ1MDQ2MjM0MDk0NTc3NDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | faa6fc884ce8ad3add6aa9a56308847bc8e03053463d793cc9129a9abaae80b8 |
| hovercard-subject-tag | issue:250788413 |
| 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/17849/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cfe4a073d129a6874a9873abb472a1ad025047eacf1a325e03207424a317b709/microsoft/TypeScript/issues/17849 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cfe4a073d129a6874a9873abb472a1ad025047eacf1a325e03207424a317b709/microsoft/TypeScript/issues/17849 |
| og:image:alt | TypeScript Version: 2.4.2 Code interface HasIndex { [key : string] : number } interface HasPropWithHasIndex { hasIndex ?: HasIndex } // one - works fine const obj1 : HasPropWithHasIndex = { hasInde... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bradzacher |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width