Title: Removing optional modifier also removes `undefined` from value type · Issue #31025 · microsoft/TypeScript · GitHub
Open Graph Title: Removing optional modifier also removes `undefined` from value type · Issue #31025 · microsoft/TypeScript
X Title: Removing optional modifier also removes `undefined` from value type · Issue #31025 · microsoft/TypeScript
Description: TypeScript Version: 3.3.3333 Search Terms: NonPartial, remove optional modifier Code // A *self-contained* demonstration of the problem follows... // Test this by running `tsc` on the command-line, rather than through another build tool ...
Open Graph Description: TypeScript Version: 3.3.3333 Search Terms: NonPartial, remove optional modifier Code // A *self-contained* demonstration of the problem follows... // Test this by running `tsc` on the command-line,...
X Description: TypeScript Version: 3.3.3333 Search Terms: NonPartial, remove optional modifier Code // A *self-contained* demonstration of the problem follows... // Test this by running `tsc` on the command-line,...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/31025
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Removing optional modifier also removes `undefined` from value type","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\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.3.3333\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** NonPartial, remove optional modifier\r\n\r\n**Code**\r\n\r\n```ts\r\n// A *self-contained* demonstration of the problem follows...\r\n// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.\r\n\r\ninterface OptClass {\r\n opt?: number;\r\n}\r\n\r\ntype NonPartialIsh = {[K in keyof OptClass]-?: OptClass[K] | undefined};\r\n\r\nconst test = {opt: undefined};\r\n\r\nverify\u003cNonPartialIsh>(test); // should NOT be error, but shows error\r\n\r\nfunction verify\u003cT>(a: T) {}\r\n```\r\n\r\n**Expected behavior:**\r\n* Should not have any error.\r\n* `NonPartialish.opt` type should support `undefined`.\r\n\r\n**Actual behavior:**\r\n* Throws the following error:\r\n\r\n```\r\nERROR(12,23): : Argument of type '{ opt: undefined; }' is not assignable to parameter of type 'NonPartialIsh'.\r\n Types of property 'opt' are incompatible.\r\n Type 'undefined' is not assignable to type 'number'.\r\nTranspiled code follows despite errors.\r\n```\r\n* `NonPartialish.opt` type does not support `undefined`.\r\n\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> https://www.typescriptlang.org/play/#src=%2F%2F%20A%20*self-contained*%20demonstration%20of%20the%20problem%20follows...%0D%0A%2F%2F%20Test%20this%20by%20running%20%60tsc%60%20on%20the%20command-line%2C%20rather%20than%20through%20another%20build%20tool%20such%20as%20Gulp%2C%20Webpack%2C%20etc.%0D%0A%0D%0Ainterface%20OptClass%20%7B%0D%0A%20%20opt%3F%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Atype%20NonPartialIsh%20%3D%20%7B%5BK%20in%20keyof%20OptClass%5D-%3F%3A%20OptClass%5BK%5D%20%7C%20undefined%7D%3B%0D%0A%0D%0Aconst%20test%20%3D%20%7Bopt%3A%20undefined%7D%3B%0D%0A%0D%0Averify%3CNonPartialIsh%3E(test)%3B%20%20%2F%2F%20should%20NOT%20be%20error%2C%20but%20shows%20error%0D%0A%0D%0Afunction%20verify%3CT%3E(a%3A%20T)%20%7B%20%7D%0D%0A\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/ienzam","@type":"Person","name":"ienzam"},"datePublished":"2019-04-18T22:10:44Z","url":"https://github.com/microsoft/TypeScript/issues/31025"}
| 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:f8d76717-2191-1116-d08a-5f75739894d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C088:2E654B:BC3EAC:F58BF4:6B0532D1 |
| html-safe-nonce | 41a563de3ae1bea17cc96a7d185dd6047aae34d5018426854e8084636c488f38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDg4OjJFNjU0QjpCQzNFQUM6RjU4QkY0OjZCMDUzMkQxIiwidmlzaXRvcl9pZCI6IjUwNTg5MzY1ODk4NDYzOTM1NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0f9c0493a1785a33e5afbdded97135284bd51f26751908e7a6766a2ac471a135 |
| hovercard-subject-tag | issue:434979127 |
| 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/31025/issue_layout |
| twitter:image | https://opengraph.githubassets.com/67b46a580bf3ee625b11bdb940d170874d21591c35447dd1db36ab83679f82e3/microsoft/TypeScript/issues/31025 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/67b46a580bf3ee625b11bdb940d170874d21591c35447dd1db36ab83679f82e3/microsoft/TypeScript/issues/31025 |
| og:image:alt | TypeScript Version: 3.3.3333 Search Terms: NonPartial, remove optional modifier Code // A *self-contained* demonstration of the problem follows... // Test this by running `tsc` on the command-line,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ienzam |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width