Title: Generic Extended Types not inferring Correctly · Issue #48741 · microsoft/TypeScript · GitHub
Open Graph Title: Generic Extended Types not inferring Correctly · Issue #48741 · microsoft/TypeScript
X Title: Generic Extended Types not inferring Correctly · Issue #48741 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms Generic Extended Types not inferring Correctly Inferred generics 🕗 Version & Regression Information All versions have this problem. This is the behavior in every version I tried, and I reviewed the FAQ for entri...
Open Graph Description: Bug Report 🔎 Search Terms Generic Extended Types not inferring Correctly Inferred generics 🕗 Version & Regression Information All versions have this problem. This is the behavior in every version I...
X Description: Bug Report 🔎 Search Terms Generic Extended Types not inferring Correctly Inferred generics 🕗 Version & Regression Information All versions have this problem. This is the behavior in every versi...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48741
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic Extended Types not inferring Correctly","articleBody":"# Bug Report\r\n### 🔎 Search Terms\r\n\r\n* Generic Extended Types not inferring Correctly \r\n* Inferred generics\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nAll versions have this problem.\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about \"Inferred types & Generics\"\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.0-dev.20220417#code/C4TwDgpgBAqgdgdQE4EMwDUUBsCuEA8AKgHxQC8UhUEAHsBHACYDOUAgkqiPgJZwBmEJJUy4IpAPwjseKAB8ocHFixQAXIogA3IQG4AUPtCRYiVGADyAIwBWEAMbAipCgG99UKAG0AClD5QANYQIAD2-JQAuhrwyGiieES+kcQGAL4G+nz0SPwo9tAAIhB5ysA+SKFgrO6eYJVgAIwaSgC2VkJekQZ1DQBMGszASHwA5l3phtlCeQVQAKJ0DIwQjBVVrLT0TKzFpVjlDTUeUPVVAMwaVqGhWBAocBP6aYb2WCjMrADKOJBIANLvT7OKC1KA4OAAd3MkEYAEIYmY0NY7I5nD0oKERqM+NgEZRJvoAPREqAASWAUDQkBQSFYwFCUFa0GAAAsUJS2dAVvtKaMGEIePYoMZoDxmHAAOSUjpjKn2eyhCH0RhQfhYqCsoQQAB0xNJZKgkKVWFVtEgjkoIsZHSplLuH0pexQZXW1SpTA9qttKCsd2tUH5nPZnPAYwANJrQpDtEJIzxKfr-KwIb7-Qz-AIhCKtSKw3BRnq3h9vjgrICS0RqEsdlBna6juQ6yUXQc3cxSFtlqW-hXgSRQSdmWzQoxGgAKACUYM8JKgCFZICgjFCEHpueMcrgoUpxqQgU12okJ08bPFOoh0Opqx1ZyaTcaGJeL30xc+UAscAgxQgf2r2xYKAfnLIFmHwRYANWdtSDBYdWVHPopxnKA5wXJcVzXHMWXzUYjSxA8tSQCBj08U9WXPS8YRvO9GgfDEyIoqEqMYW8GnOJs8iwZgICfZ5DH0IA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype UnWrapValue\u003cT> = T extends Array\u003cinfer TValue> ? TValue | null : never;\r\n\r\ntype UnWrapObject\u003cT> = {\r\n [P in keyof T]: UnWrapValue\u003cT[P]>;\r\n};\r\n\r\ninterface DefaultProps {\r\n prop1: number[];\r\n prop2: string[];\r\n}\r\n\r\ninterface ExtendedProps extends DefaultProps {\r\n prop3: boolean[];\r\n}\r\n\r\nclass SuperKlass\u003cT> {\r\n unwrapped!: UnWrapObject\u003cT>;\r\n original!: T;\r\n}\r\n\r\n// It appears to me that the default generic type isn't being accounted for here.\r\n// I would expect T to be at least DefaultProps and and be able to get that typing, however, it \r\n// is unable to infer the typing.\r\nclass SubKlass\u003cT extends DefaultProps = DefaultProps> extends SuperKlass\u003cT> {\r\n method1(){\r\n // Why does the typing NOT work here?\r\n this.unwrapped.prop1 = 1;\r\n }\r\n}\r\n\r\nclass OneDeeper extends SubKlass\u003cExtendedProps> {\r\n method2(){\r\n // Why does the typing work here?\r\n this.unwrapped.prop1 = 1;\r\n this.unwrapped.prop3 = false;\r\n }\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\nUnwrapping a constrained generic type with \"infer\" fails to do so properly.\r\n\r\n### 🙂 Expected behavior\r\n\"this.unwrapped.prop1\" should be type \"string\" within \"SubKlass\". \r\n","author":{"url":"https://github.com/jaredjbarnes","@type":"Person","name":"jaredjbarnes"},"datePublished":"2022-04-17T19:05:35Z","url":"https://github.com/microsoft/TypeScript/issues/48741"}
| 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:aa58425c-9ddd-2ef5-b3d6-c37873d59def |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A802:E9D16:139C5DB:18D2FF2:6B015F5B |
| html-safe-nonce | 8c9c3f87cda1448dde9f7756265c7c5d89f6d672feb21f756ee972bd5ec8d920 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODAyOkU5RDE2OjEzOUM1REI6MThEMkZGMjo2QjAxNUY1QiIsInZpc2l0b3JfaWQiOiI4NzU2MzczNTQ4NzAxOTMzNDAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1db65314679316da3b3e6a97c2135b44dd1a5bb02cee13b67ab8435076064e3c |
| hovercard-subject-tag | issue:1206458712 |
| 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/48741/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2dd6235a3dbd87e23c8d23acb49936145daffacfe02ef453a3679327da19c1b0/microsoft/TypeScript/issues/48741 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2dd6235a3dbd87e23c8d23acb49936145daffacfe02ef453a3679327da19c1b0/microsoft/TypeScript/issues/48741 |
| og:image:alt | Bug Report 🔎 Search Terms Generic Extended Types not inferring Correctly Inferred generics 🕗 Version & Regression Information All versions have this problem. This is the behavior in every version I... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jaredjbarnes |
| 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