Title: Two types should only be compatible if their members are compatible - even if all these members are optional · Issue #12904 · microsoft/TypeScript · GitHub
Open Graph Title: Two types should only be compatible if their members are compatible - even if all these members are optional · Issue #12904 · microsoft/TypeScript
X Title: Two types should only be compatible if their members are compatible - even if all these members are optional · Issue #12904 · microsoft/TypeScript
Description: I wanted to see if I can update definitions a MongoDB filter object, which utilizes these expressions. Below is just a start, but I already see an issue when the code compiles when it should not. This issue possibly has similar underlyin...
Open Graph Description: I wanted to see if I can update definitions a MongoDB filter object, which utilizes these expressions. Below is just a start, but I already see an issue when the code compiles when it should not. T...
X Description: I wanted to see if I can update definitions a MongoDB filter object, which utilizes these expressions. Below is just a start, but I already see an issue when the code compiles when it should not. T...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12904
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Two types should only be compatible if their members are compatible - even if all these members are optional","articleBody":"I wanted to see if I can update definitions a MongoDB filter object, which utilizes [these expressions](https://docs.mongodb.com/manual/reference/operator/query/#query-selectors). Below is just a start, but I already see an issue when the code compiles when it should not. This issue possibly has similar underlying issue as #12769\r\n\r\n**TypeScript Version:** 2.1.4\r\n\r\n**Code**\r\n\r\n```ts\r\ntype MongoFilter\u003cT> = $and\u003cT> | $or\u003cT> | propertyRule\u003cT>;\r\n\r\ntype logical\u003cT> = $and\u003cT> | $or\u003cT>;\r\n\r\ntype $and\u003cT> = { $and: Array\u003clogical\u003cT> | propertyRule\u003cT>> }\r\ntype $or\u003cT> = { $or: Array\u003clogical\u003cT> | propertyRule\u003cT>> }\r\n\r\ntype propertyRule\u003cT> = {\r\n [P in keyof T]?: T[P] | comparison\u003cT[P]>\r\n}\r\n\r\ntype comparison\u003cV> = $eq\u003cV> | $gt | $lt;\r\n\r\ntype $eq\u003cV> = { $eq: V };\r\ntype $gt = { $gt: number };\r\ntype $lt = { $lt: number };\r\n\r\n// See if MongoFilter works:\r\ninterface Person {\r\n id: number;\r\n name: string;\r\n age: number;\r\n}\r\n\r\n// should compile\r\nlet f1: MongoFilter\u003cPerson> = { $or: [{ id: 1 }, { name: 'dima' }] };\r\nlet f2: MongoFilter\u003cPerson> = { $and: [{ id: 1 }] };\r\nlet f3: MongoFilter\u003cPerson> = { id: 1 };\r\n\r\n// should not compile\r\nlet w1: MongoFilter\u003cPerson> = { wrong: 1 }; // does not compile - good\r\nlet w2: MongoFilter\u003cPerson> = { $or: [{ wrong: 1 }] }; // compiles\r\n```\r\n\r\n**Expected behavior:**\r\nCode below should not compile\r\n```ts\r\nlet w1: MongoFilter\u003cPerson> = { $or: [{ wrong: 1 }] };\r\n```\r\n\r\n**Actual behavior:**\r\nBut it does","author":{"url":"https://github.com/DmitryEfimenko","@type":"Person","name":"DmitryEfimenko"},"datePublished":"2016-12-14T07:54:27Z","url":"https://github.com/microsoft/TypeScript/issues/12904"}
| 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:a8179e47-0915-43c2-d96c-2d8511432069 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 87DC:2409E2:4C8EBA:663DD5:6B00A532 |
| html-safe-nonce | 3f23ab0fbca95db5bd7e580fc529c48c77d468ac9a37f1812176f251c2e489a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0RDOjI0MDlFMjo0QzhFQkE6NjYzREQ1OjZCMDBBNTMyIiwidmlzaXRvcl9pZCI6Ijg3MTA2MTAwNzUxNjI1NTE2MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c34222c998764f9af536884353d709d8715e556de9a5bf9aa3fb7129bb32e7d8 |
| hovercard-subject-tag | issue:195463287 |
| 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/12904/issue_layout |
| twitter:image | https://opengraph.githubassets.com/011c2844509aa75a2acf2ba6f65c448b518385327d92359f2a8d807db0dc01b1/microsoft/TypeScript/issues/12904 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/011c2844509aa75a2acf2ba6f65c448b518385327d92359f2a8d807db0dc01b1/microsoft/TypeScript/issues/12904 |
| og:image:alt | I wanted to see if I can update definitions a MongoDB filter object, which utilizes these expressions. Below is just a start, but I already see an issue when the code compiles when it should not. T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DmitryEfimenko |
| hostname | github.com |
| expected-hostname | github.com |
| None | 455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a |
| 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 | 2f575159976167242d488c0b062eb355c4e198b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width