Title: Using a mapped type, can't Exclude "undefined" from an optional property · Issue #24067 · microsoft/TypeScript · GitHub
Open Graph Title: Using a mapped type, can't Exclude "undefined" from an optional property · Issue #24067 · microsoft/TypeScript
X Title: Using a mapped type, can't Exclude "undefined" from an optional property · Issue #24067 · microsoft/TypeScript
Description: The example below shows how one ought to be able to implement the opposite of the mapped type Partial
Open Graph Description: The example below shows how one ought to be able to implement the opposite of the mapped type Partial
X Description: The example below shows how one ought to be able to implement the opposite of the mapped type Partial<T>, which should remove undefined from the type of every single property in an interface....
Opengraph URL: https://github.com/microsoft/TypeScript/issues/24067
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using a mapped type, can't Exclude \"undefined\" from an optional property","articleBody":"The example below shows how one ought to be able to implement the opposite of the mapped type `Partial\u003cT>`, which should *remove* `undefined` from the type of every single property in an interface.\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.9.0-dev.201xxxxx\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\nexclude undefined mapped optional\r\n\r\n**Code**\r\n\r\n```ts\r\ntype NeverUndefined\u003cT> = {\r\n [K in keyof T]: Exclude\u003cT[K], undefined>;\r\n}\r\n\r\ninterface MyInterface {\r\n undef: undefined\r\n optionalString?: string;\r\n stringOrUndefined: string | undefined;\r\n definedString: string;\r\n}\r\n\r\ntype NeverUndefinedMyInterface = NeverUndefined\u003cMyInterface>;\r\n```\r\n\r\n**Expected behavior:**\r\n```ts\r\n// typeof NeverUndefinedMyInterface\r\ninterface NeverUndefinedMyInterface {\r\n undef: never;\r\n optionalString: string;\r\n stringOrUndefined: string;\r\n definedString: string;\r\n}\r\n```\r\n\r\n**Actual behavior:**\r\n```ts\r\n// typeof NeverUndefinedMyInterface\r\ninterface NeverUndefinedMyInterface {\r\n undef: never;\r\n optionalString: string | undefined;\r\n stringOrUndefined: string;\r\n definedString: string;\r\n}\r\n```\r\n**(notice that optionalString still contains `undefined` in its type definition)**\r\n\r\n**Playground Link:**\r\nhttps://www.typescriptlang.org/play/#src=type%20NeverUndefined%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BK%20in%20keyof%20T%5D%3A%20Exclude%3CT%5BK%5D%2C%20undefined%3E%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20MyInterface%20%7B%0D%0A%20%20%20%20undef%3A%20undefined%3B%0D%0A%20%20%20%20optionalString%3F%3A%20string%3B%0D%0A%20%20%20%20stringOrUndefined%3A%20string%20%7C%20undefined%3B%0D%0A%20%20%20%20definedString%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20NeverUndefinedMyInterface%20%3D%20NeverUndefined%3CMyInterface%3E%3B\r\n \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> \r\n\r\n**Related Issues:**\r\nNone\r\n","author":{"url":"https://github.com/acshef","@type":"Person","name":"acshef"},"datePublished":"2018-05-11T19:31:47Z","url":"https://github.com/microsoft/TypeScript/issues/24067"}
| 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:5c798127-3274-2148-dfe4-3179833b590c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C588:1760D:1FEBA23:29D06AE:6B053B78 |
| html-safe-nonce | e760ab45555bbf7e01a388f790b035bd5b3c913facb32ca779cad2e56bb6f7e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTg4OjE3NjBEOjFGRUJBMjM6MjlEMDZBRTo2QjA1M0I3OCIsInZpc2l0b3JfaWQiOiI0NDExNjU1MDkxMDA3MDc3MjQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8d6d11387e57adc4533b1f75ac598c4cc11b5f0e3c734c336a35fc9020a88ef2 |
| hovercard-subject-tag | issue:322409549 |
| 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/24067/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3f154f527c583ef3510571971403ac8cea1505674d85b4e1bb239cee11a555c8/microsoft/TypeScript/issues/24067 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3f154f527c583ef3510571971403ac8cea1505674d85b4e1bb239cee11a555c8/microsoft/TypeScript/issues/24067 |
| og:image:alt | The example below shows how one ought to be able to implement the opposite of the mapped type Partial |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | acshef |
| 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