Title: When creating a mapped type of an indexed type it extends too liberal · Issue #32484 · microsoft/TypeScript · GitHub
Open Graph Title: When creating a mapped type of an indexed type it extends too liberal · Issue #32484 · microsoft/TypeScript
X Title: When creating a mapped type of an indexed type it extends too liberal · Issue #32484 · microsoft/TypeScript
Description: TypeScript Version: 3.6.0-dev.20190719 Search Terms: Mapped types extends Index types Code type constr
Open Graph Description: TypeScript Version: 3.6.0-dev.20190719 Search Terms: Mapped types extends Index types Code type constr
X Description: TypeScript Version: 3.6.0-dev.20190719 Search Terms: Mapped types extends Index types Code type constr<Source, Tgt> = {[K in keyof Source]: string } &Pick<Tgt, Exclude<keyof Tgt, ke...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32484
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"When creating a mapped type of an indexed type it extends too liberal","articleBody":"**TypeScript Version:** 3.6.0-dev.20190719\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\nMapped types extends Index types\r\n\r\n**Code**\r\n\r\n```ts\r\ntype constr\u003cSource, Tgt> = {[K in keyof Source]: string } &Pick\u003cTgt, Exclude\u003ckeyof Tgt, keyof Source>> \r\n\r\n\r\ntype s = constr\u003c{}, {\r\n [key: string]: {\r\n a: string;\r\n };\r\n}>\r\ndeclare const q: s\r\nq[\"asd\"].a.substr(1) //see: a is a string\r\nq[\"asd\"].b //and of course b does not exist (this line will have an error)\r\n\r\n//but I expect the following line to error as well\r\nconst d: {[key: string]: {a: string, b: string}} = q\r\n//and verify to be \"no\" (instead it is \"yes\")\r\ntype verify = s extends {[key: string]: {a: string, b: string}} ? \"yes\" : \"no\"\r\n\r\n// the error _is_ shown if you construct a (seemingly identical) type by hand\r\ntype sManual = {} & Pick\u003c{\r\n [key: string]: {\r\n a: string;\r\n };\r\n}, string | number>\r\ndeclare const qManual: sManual\r\n// see: error here\r\nconst dManual: {[key: string]: {a: string, b: string}} = qManual\r\n\r\n//the error is also shown if I replace the indexed type with an actual property\r\ntype s2 = constr\u003c{}, {\r\n asd: {\r\n a: string;\r\n };\r\n}>\r\ndeclare const q2: s2\r\nq2.asd.a.substr(1) //this is the same\r\nq2.asd.b //this also\r\n\r\n\r\n//But this is now an error (as it should be)\r\nconst d2: {asd: {a: string, b: string}} = q2\r\n\r\n//and this is \"no\" (as it should be)\r\ntype verify2 = s2 extends {asd: {a: string, b: string}} ? \"yes\" : \"no\"\r\n\r\n```\r\n\r\n**Expected behavior:**\r\nAs described inline. I do not think `q` should be assignable to `d`\r\n**Actual behavior:**\r\n`q` is assignable to `d`\r\n\r\n**Playground Link:** http://www.typescriptlang.org/play/#code/C4TwDgpgBAxg9gOwM7AE4B4DKcCuqYQA0UAKgObAB8UAvFAN4DaA0lAJYJQDWEIcAZlGx4CAXQBcUFKg5koAXygAyAApsYXdOWDEAogA8YAGxwATCOh59B24lYFDc+CJWoAoD6EhTasRNPR6eWJ6NygoRitJaVkJBjDwxIBDaLRZAG4E+Uz5SjdzYyTUaHhkYCgAR2i3CsYAIiSkUzrRADok1qQcACNpAAoARgBKKAB6UaQICEkk9iQoWZiEMhr6xua27vDxpIRTKAd4PEmoLdM4CHmEOHKIfTYUKD7gAAsHqCMOaAB3NiMjKAvJIAN2guygEFQqDgqCGHnG3Rw5QAkhD9JAYOVXtB+HB-nBfssPl8oMA4BCoTCFvNvhB-m5So9TJImFEpGllnF6Cl2TJlsRuqk+WR5Io6BU3Ds9lBQTJ+CBSeTutA6tc6k8OCgIEl9mxyu86iBLnU4V5oLK2PLfPM7sAIHt5qzeELYiyeUsyAKXctRVAAPxQQ3GqCSVVwOrw0akl7QSHQ1BQAD6D0T0eh304lqgfBwfjKqBwmIWT0mEAAtrIjAq2OYEMB1EkjCMzacFUC9m4W0gALK7HCN3wMRRKKBqDSBBLhSLO3mu+KJBcLb1kTIL7JuYKzokAHygCBwZeVqDyBSMRRK-nKFV7+8b0Rv-aMkqjpckcapMeKDMvUFMD7vDDTiAy5cu6HKeqcy6+uK-5Ps+yKCKixRgGeBDRtAHDmPoED7C2vyvAsnBJJij5QGA0KQKgoCduA0BIAATL4jJoIEm6hOE6wspOyTLquCg5CeECFMUeaPBU9HRPRNT0e0TTtJ0PT9MMYyjK87zvNiUhJGWEDSbJpitFs4xqfMjZIHAHjPgAQki0bqVcBKERS8ZPI07DlEgLy4EY+zKnCzG-hJDCccFy5eluIpipUUnPrsuFvPMBpqq5iUeV5OA+acECmrRMqQpaICMXQDFonaDrBU0bphZBEW+gGQZIOqoZqm4QA\r\n\r\n**Related Issues:** Sorry, no. But as evidenced by my search terms I have some trouble finding the right words to describe the bug\r\n","author":{"url":"https://github.com/jauco","@type":"Person","name":"jauco"},"datePublished":"2019-07-19T15:19:46Z","url":"https://github.com/microsoft/TypeScript/issues/32484"}
| 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:bdfd98dc-5360-b122-1cd8-2ce9f284bbe4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 941C:D1D28:7FE600:A9C87F:6B01AE8E |
| html-safe-nonce | 36f79f8b21effbdcfbf431d8c254d0c68da4523fd355102508fd3c9d571529f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDFDOkQxRDI4OjdGRTYwMDpBOUM4N0Y6NkIwMUFFOEUiLCJ2aXNpdG9yX2lkIjoiNzE5OTMyMjcyMjc4NTE0NDQ2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aafc7c21d3a0ed34b250fc144e167b49f7921ecadba7584ab631062881d148ff |
| hovercard-subject-tag | issue:470379797 |
| 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/32484/issue_layout |
| twitter:image | https://opengraph.githubassets.com/16a6eda78e881584157bc1cdad0d475a31bd7addeb1dfd3cef74c478244a5cc7/microsoft/TypeScript/issues/32484 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/16a6eda78e881584157bc1cdad0d475a31bd7addeb1dfd3cef74c478244a5cc7/microsoft/TypeScript/issues/32484 |
| og:image:alt | TypeScript Version: 3.6.0-dev.20190719 Search Terms: Mapped types extends Index types Code type constr |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jauco |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width