Title: Compilation exception in mapped type · Issue #13044 · microsoft/TypeScript · GitHub
Open Graph Title: Compilation exception in mapped type · Issue #13044 · microsoft/TypeScript
X Title: Compilation exception in mapped type · Issue #13044 · microsoft/TypeScript
Description: TypeScript Version: nightly (2.2.0-dev.20161219) Code type Foo
Open Graph Description: TypeScript Version: nightly (2.2.0-dev.20161219) Code type Foo
X Description: TypeScript Version: nightly (2.2.0-dev.20161219) Code type Foo<T, F extends keyof T> = { pf: {[P in F]?: T[P]}, pt: {[P in T]?: T[P]}, // note: should be in keyof T }; type O = {x: number, y:...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/13044
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Compilation exception in mapped type","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:** nightly (2.2.0-dev.20161219)\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Foo\u003cT, F extends keyof T> = {\r\n pf: {[P in F]?: T[P]},\r\n pt: {[P in T]?: T[P]}, // note: should be in keyof T\r\n};\r\ntype O = {x: number, y: boolean};\r\nlet o: O = {x: 5, y: false};\r\nlet f: Foo\u003cO, 'x'> = {\r\n pf: {x: 7},\r\n pt: {x: 7, y: false},\r\n};\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nCompiling only the first type declaration produces the following expected error:\r\n```\r\n$ node node_modules/typescript/bin/tsc test.ts\r\ntest.ts(4,16): error TS2322: Type '{}' is not assignable to type 'string'.\r\ntest.ts(4,21): error TS2536: Type 'P' cannot be used to index type 'T'.\r\n```\r\n\r\n**Actual behavior:**\r\nCompiling the whole example with a clean nightly install without `tsconfig` produces:\r\n```\r\n$ node node_modules/typescript/bin/tsc test.ts\r\nC:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:49834\r\n throw e;\r\n ^\r\n\r\nTypeError: Cannot read property 'flags' of undefined\r\n at getModifiersTypeFromMappedType (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:23125:60)\r\n at resolveMappedTypeMembers (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:23068:49)\r\n at resolveStructuredTypeMembers (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:23153:25)\r\n at getPropertyOfType (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:23307:32)\r\n at C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:28345:47\r\n at applyToContextualType (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:28321:24)\r\n at getTypeOfPropertyOfContextualType (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:28344:20)\r\n at getContextualTypeForObjectLiteralElement (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:28368:40)\r\n at getContextualType (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:28442:28)\r\n at checkExpressionForMutableLocation (C:\\Users\\...\\Documents\\TCM\\git\\tmp\\node_modules\\typescript\\lib\\tsc.js:31213:69)\r\n```","author":{"url":"https://github.com/zamb3zi","@type":"Person","name":"zamb3zi"},"datePublished":"2016-12-20T04:23:55Z","url":"https://github.com/microsoft/TypeScript/issues/13044"}
| 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:92b6c72e-eafb-ed57-f2fe-35fd50ef6503 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DBF6:EA06E:542CC2:6E7B85:6B00CB0F |
| html-safe-nonce | 9fde5f381ea4d3fa9aed76dd691f741c686a0f258549aba2a1221554b9f4f1ff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkY2OkVBMDZFOjU0MkNDMjo2RTdCODU6NkIwMENCMEYiLCJ2aXNpdG9yX2lkIjoiNTM5Nzg1NDk0NTk1OTUyOTIzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5c3b429ab8931b10cf50f9ab6123bdac4c00dc5d9e0868f409591ec29503dc7c |
| hovercard-subject-tag | issue:196583454 |
| 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/13044/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc59380d64a085e309a9c0db05111accd1ede162d84325a97fc6d097d61f4733/microsoft/TypeScript/issues/13044 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc59380d64a085e309a9c0db05111accd1ede162d84325a97fc6d097d61f4733/microsoft/TypeScript/issues/13044 |
| og:image:alt | TypeScript Version: nightly (2.2.0-dev.20161219) Code type Foo |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zamb3zi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width