Title: Record
Open Graph Title: Record
X Title: Record
Description: Bug Report 🔎 Search Terms Record
Open Graph Description: Bug Report 🔎 Search Terms Record
X Description: Bug Report 🔎 Search Terms Record<string, never> object condition Record<string, never> branch is not recognized on condition over object 🕗 Version & Regression Information This is t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47071
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Record\u003cstring, never> branch is not recognized on condition over object ","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\n\r\nRecord\u003cstring, never>\r\nobject condition\r\nRecord\u003cstring, never> branch is not recognized on condition over object \r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This is the behavior in every version I tried, from 3.3.3 to 4.5.2 and nightly\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.5.2&ssl=16&ssc=50&pln=1&pc=1#code/C4TwDgpgBAwg9gOwGYEsDmUA8AVKEAewECAJgM5RwBGAVhAMbAB8UAvAFBRQBkUA3lAC2AQ1LDgcAE4gAXFAQBXQVQiSoAX048oAClwEipCgCUGUkpjLBJKBGgA08iADdVTLVwD8-KPQVW4QU85BVIIVAQIEg0PKDkBPwDBOVx1AEoAbnZ2ekQrKCQENix9QmJySloGYGLTXMkLKxs7R0jXSSYmHVzkdDl4XrQcJjS2Fj5YnvzEiUFintQ0ADoZwIyoAHoNqAB1SUQHKFBIMnobMBqUCgQ4GuEAd2FJaGAAC3EoFBr6USgVKFCJHCtii2S4XC2UAAInAoGRAhA3rY0JM8nAADYQJbouBoHQAeSqjCWAGsICAyN1-LM0pl2Jp2IUdAIRGIJNI5ABGDSjSEAIX2ZIQjgABgt0CtqYERb5fv9AcDIiRskyWaISOIpLIoJzHKtkj5hHIAOTCY0aHmbbY7KQkshAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype Config \u003cT extends object> =\r\n & { mandatory: number }\r\n & (T extends Record\u003cstring, never>\r\n ? { custom?: undefined }\r\n : { custom: T });\r\n\r\nconst fn = \u003cT extends object = Record\u003cstring, never>>(config: Config\u003cT>) => {\r\n const custom = config.custom; // Wrong, typescript is not aware that it can be undefined\r\n\r\n // Do something\r\n console.log(Object.keys(custom));\r\n}\r\n\r\nfn({ mandatory: 1 }) // Broken, `config.custom` can be undefined\r\n\r\nfn({ mandatory: 1, custom: { a: 'a' } }) // Works\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n\u003c!-- What happened, and why it was wrong -->\r\nTypescript says that the variable `const custom` inside `fn()` is of type `object`, but it's not true, it can be undefined. Running the code throws an error, even though typescript doesn't see anything wrong with code.\r\n\r\n### 🙂 Expected behavior\r\n\r\nT variable `const custom` inside `fn()` should be of type `object | undefined`.\r\n","author":{"url":"https://github.com/javiertury","@type":"Person","name":"javiertury"},"datePublished":"2021-12-08T21:29:54Z","url":"https://github.com/microsoft/TypeScript/issues/47071"}
| 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:3a46835c-25b7-9879-6040-1ce576c389c5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6D8:20AA01:37AA400:46B5034:6B01DA81 |
| html-safe-nonce | b6a12bf46dd1a26ae459c9d8e30fb8606c19c4e32e6672641e456ce2eea6d534 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkQ4OjIwQUEwMTozN0FBNDAwOjQ2QjUwMzQ6NkIwMURBODEiLCJ2aXNpdG9yX2lkIjoiNjE4MDYyNjA5MzAwMzg4OTI4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1eae766328815cca31ef7bf61843d8772ff369334de3ea54679d06b43a687ae1 |
| hovercard-subject-tag | issue:1074848194 |
| 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/47071/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7825711d9f85c420b8330cf030eaea22ac65bbe58833bde6cf9c1a74d2bb73a8/microsoft/TypeScript/issues/47071 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7825711d9f85c420b8330cf030eaea22ac65bbe58833bde6cf9c1a74d2bb73a8/microsoft/TypeScript/issues/47071 |
| og:image:alt | Bug Report 🔎 Search Terms Record |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | javiertury |
| 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