Title: `Omit` helper loses type information when used with extended Records. · Issue #36981 · microsoft/TypeScript · GitHub
Open Graph Title: `Omit` helper loses type information when used with extended Records. · Issue #36981 · microsoft/TypeScript
X Title: `Omit` helper loses type information when used with extended Records. · Issue #36981 · microsoft/TypeScript
Description: TypeScript Version: 3.8 & Nightly Search Terms: Omit Record Any Loses type information Expected behavior: I expect the following types to be as described in the inline comments. type AnyRecord = Record
Open Graph Description: TypeScript Version: 3.8 & Nightly Search Terms: Omit Record Any Loses type information Expected behavior: I expect the following types to be as described in the inline comments. type AnyRecord = Re...
X Description: TypeScript Version: 3.8 & Nightly Search Terms: Omit Record Any Loses type information Expected behavior: I expect the following types to be as described in the inline comments. type AnyRecord ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36981
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Omit` helper loses type information when used with extended Records.","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n**TypeScript Version:** 3.8 & Nightly\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\n\r\n- Omit\r\n- Record\r\n- Any\r\n- Loses type information\r\n\r\n**Expected behavior:**\r\n\r\nI expect the following types to be as described in the inline comments.\r\n```ts\r\ntype AnyRecord = Record\u003cstring, any>;\r\ninterface ExtendsAny extends AnyRecord {\r\n myKey1: string;\r\n myKey2: string;\r\n}\r\n// ExtendsAny['myKey1'] === string\r\n// ExtendsAny['otherKey'] === any\r\n\r\ntype OmitsKey = Omit\u003cExtendsAny, \"myKey2\">;\r\n// OmitsKey['myKey'] === string\r\n// OmitsKey['otherKey'] === any\r\n```\r\n\r\nPlease note that this works without the omit, or without the record, but not when both are used together.\r\n\r\n**Actual behavior:**\r\n\r\nWhat actually happens is that after using omit, all keys become \"any\" and any information for code completion, etc that the specifically defined keys even exist, are removed, even thought they were working in the original extension.\r\n\r\n```ts\r\ntype AnyRecord = Record\u003cstring, any>;\r\ninterface ExtendsAny extends AnyRecord {\r\n myKey1: string;\r\n myKey2: string;\r\n}\r\n// ExtendsAny['myKey1'] === string\r\n// ExtendsAny['otherKey'] === any\r\n\r\ntype OmitsKey = Omit\u003cExtendsAny, \"myKey2\">;\r\n// 🚨Problem here 🚨\r\n// OmitsKey['myKey1'] === any\r\n// OmitsKey['otherKey'] === any\r\n\r\n\r\nconst instance: OmitsKey = {\r\n myKey1: \"test\",\r\n}\r\n// 🚨 When typing this no autocomplete is provided for myKey1 🚨\r\ninstance.myKey1.\r\n```\r\n\r\n\u003c!-- Did you find other bugs that looked similar? -->\r\n**Related Issues:**\r\n\r\n- https://github.com/microsoft/TypeScript/issues/27883\r\n\r\n**Potential Workaround**\r\n\r\nIn the meantime, I am redefining the base interface (very large) because it comes from a library without the record type mixed in. I do my omit, then add it back in afterwards.\r\n\r\n**Code**\r\n```ts\r\n/**\r\n * @copyright 2020 Adam (charrondev) Charron\r\n * @license MIT\r\n */\r\n\r\nexport interface IBase\u003cT = number> {\r\n baseProp: T;\r\n baseProp2: T;\r\n baseFunction: () => T;\r\n}\r\n\r\nconst base: IBase\u003cnumber> = {\r\n baseProp: 0,\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n};\r\n\r\n// number\r\nbase.baseProp;\r\n\r\n///\r\n/// Without the omit\r\n///\r\ntype AnyRecord = Record\u003cstring, any>;\r\n\r\ninterface IExtend\u003cT> extends IBase\u003cT>, AnyRecord {\r\n extendProp: T;\r\n}\r\n\r\nconst extended: IExtend\u003cnumber> = {\r\n baseProp: 0,\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n extendProp: 0,\r\n};\r\n\r\n// number\r\nextended.baseProp2;\r\n\r\n///\r\n/// With an Omit\r\n///\r\ninterface IOmittedInterface extends Omit\u003cIExtend\u003cnumber>, \"baseProp\"> {}\r\n\r\nconst omitted: IOmittedInterface = {\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n};\r\n\r\n// any\r\nomitted.baseProp2;\r\n\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n```ts\r\n/**\r\n * @copyright 2020 Adam (charrondev) Charron\r\n * @license MIT\r\n */\r\nconst base = {\r\n baseProp: 0,\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n};\r\n// number\r\nbase.baseProp;\r\nconst extended = {\r\n baseProp: 0,\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n extendProp: 0,\r\n};\r\n// number\r\nextended.baseProp2;\r\nconst omitted = {\r\n baseProp2: 0,\r\n baseFunction: () => 0,\r\n};\r\n// any\r\nomitted.baseProp2;\r\n\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": false,\r\n \"alwaysStrict\": true,\r\n \"allowUnreachableCode\": false,\r\n \"allowUnusedLabels\": false,\r\n \"downlevelIteration\": false,\r\n \"noEmitHelpers\": false,\r\n \"noLib\": false,\r\n \"noStrictGenericChecks\": false,\r\n \"noUnusedLocals\": false,\r\n \"noUnusedParameters\": false,\r\n \"esModuleInterop\": true,\r\n \"preserveConstEnums\": false,\r\n \"removeComments\": false,\r\n \"skipLibCheck\": false,\r\n \"checkJs\": false,\r\n \"allowJs\": false,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": false,\r\n \"emitDecoratorMetadata\": false,\r\n \"target\": \"ES2017\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](http://www.typescriptlang.org/play/?ts=Nightly#)\r\n ","author":{"url":"https://github.com/charrondev","@type":"Person","name":"charrondev"},"datePublished":"2020-02-24T18:05:18Z","url":"https://github.com/microsoft/TypeScript/issues/36981"}
| 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:9e56bec9-8297-e0f7-709e-0c05ca6b6963 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1C4:AFBD9:53CDDE:6EC0E4:6B019EC7 |
| html-safe-nonce | 41f06e21bdd95545743bbd1070f70cb336ce9686fd4055b855b7ad5da284c320 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUM0OkFGQkQ5OjUzQ0RERTo2RUMwRTQ6NkIwMTlFQzciLCJ2aXNpdG9yX2lkIjoiNjI4NDA2Mzc2NjA3ODM5ODE1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a016c68864ac6584871383d55f97fac4616dcdb1c4f975e75e77209f76abf9a |
| hovercard-subject-tag | issue:570028273 |
| 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/36981/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2f7ad336310bb133fc31d241514b85ca7f604f001407a14b33ae1083b2907599/microsoft/TypeScript/issues/36981 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2f7ad336310bb133fc31d241514b85ca7f604f001407a14b33ae1083b2907599/microsoft/TypeScript/issues/36981 |
| og:image:alt | TypeScript Version: 3.8 & Nightly Search Terms: Omit Record Any Loses type information Expected behavior: I expect the following types to be as described in the inline comments. type AnyRecord = Re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | charrondev |
| 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