Title: Mapping generic types breaks inference/narrowing · Issue #16267 · microsoft/TypeScript · GitHub
Open Graph Title: Mapping generic types breaks inference/narrowing · Issue #16267 · microsoft/TypeScript
X Title: Mapping generic types breaks inference/narrowing · Issue #16267 · microsoft/TypeScript
Description: TypeScript Version: 2.3.4 Code interface I { x: number | null; } function generic
Open Graph Description: TypeScript Version: 2.3.4 Code interface I { x: number | null; } function generic
X Description: TypeScript Version: 2.3.4 Code interface I { x: number | null; } function generic<T extends I>(a: T, b: Partial<T>) { if (a.x != null) { a.x.toFixed(2); // OK } if (b.x != null) { b.x.t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/16267
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mapping generic types breaks inference/narrowing","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.3.4\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface I {\r\n x: number | null;\r\n}\r\n\r\nfunction generic\u003cT extends I>(a: T, b: Partial\u003cT>) {\r\n if (a.x != null) {\r\n a.x.toFixed(2); // OK\r\n }\r\n\r\n if (b.x != null) {\r\n b.x.toFixed(2); // ERROR: Property 'toFixed' does not exist on type 'T[\"x\"]'\r\n }\r\n}\r\n\r\nfunction notGeneric(a: I, b: Partial\u003cI>) {\r\n if (a.x != null) {\r\n a.x.toFixed(2); // OK\r\n }\r\n\r\n if (b.x != null) {\r\n b.x.toFixed(2); // OK\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThe mapped generic code should compile without error.\r\n\r\n**Actual behavior:**\r\n\r\nThe mapped generic code does not compile.\r\n\r\nFor context, the place I'm seeing this issue is React when interacting with `props`. The React typings for a `Component` are:\r\n\r\n```ts\r\nclass Component\u003cP, S> {\r\n props: Readonly\u003c{ children?: ReactNode }> & Readonly\u003cP>;\r\n // snip\r\n}\r\n```","author":{"url":"https://github.com/jaredru","@type":"Person","name":"jaredru"},"datePublished":"2017-06-05T19:01:14Z","url":"https://github.com/microsoft/TypeScript/issues/16267"}
| 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:9b994cff-a24c-76fd-a58e-644af600c341 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9BB2:34CAB:BD4505:F291DD:6B00FEE1 |
| html-safe-nonce | a1a281f2292582fb5e8d06fe00c710e95ffd9639c8b75a1c3dd276b7ce35aaab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QkIyOjM0Q0FCOkJENDUwNTpGMjkxREQ6NkIwMEZFRTEiLCJ2aXNpdG9yX2lkIjoiNjE0ODUwMDMwNzgzNzU4MDQ5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e915d23154d680edc5e13fdd90cb9b5caceaf9a68d271300edee4fe9df448fb0 |
| hovercard-subject-tag | issue:233678747 |
| 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/16267/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e44bf8c98f194f7c49d010aa94f4162117651fea1881dea694a546b291873595/microsoft/TypeScript/issues/16267 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e44bf8c98f194f7c49d010aa94f4162117651fea1881dea694a546b291873595/microsoft/TypeScript/issues/16267 |
| og:image:alt | TypeScript Version: 2.3.4 Code interface I { x: number | null; } function generic |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jaredru |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width