Title: [Suggestion] Override and identifier! for Mapped Type and extend interface · Issue #18567 · microsoft/TypeScript · GitHub
Open Graph Title: [Suggestion] Override and identifier! for Mapped Type and extend interface · Issue #18567 · microsoft/TypeScript
X Title: [Suggestion] Override and identifier! for Mapped Type and extend interface · Issue #18567 · microsoft/TypeScript
Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Situation There are lots of demand of more flexibility to Mapped Type. For example: Extend from a type and override some fields Turn optional field to required Only make some...
Open Graph Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Situation There are lots of demand of more flexibility to Mapped Type. For example: Extend from a type and override some fields Turn o...
X Description: TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Situation There are lots of demand of more flexibility to Mapped Type. For example: Extend from a type and override some fields Turn o...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/18567
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Suggestion] Override and identifier! for Mapped Type and extend interface","articleBody":"\u003c!-- BUGS: Please use this template. --\u003e\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript --\u003e\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md --\u003e\r\n\r\n**TypeScript Version:** 2.4.0 / nightly (2.5.0-dev.201xxxxx)\r\n2.5.2\r\n\r\n**Situation**\r\nThere are lots of demand of more flexibility to Mapped Type. For example:\r\n1. Extend from a type and override some fields\r\n1. Turn optional field to required\r\n1. Only make some specific fields to optional\r\n\r\n**Suggestion**\r\n1. **Support multiple field definition in one type, the latter definition (same fields) will overwrite the previous**\r\n1. **Support identifier! for type definition which will remove `null` and `undefined`.**\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Full = {\r\n field1: string;\r\n field2: string;\r\n ....\r\n fieldN: string;\r\n}\r\n\r\n//Suggestion 1: Multiple fields in type definition and support override\r\ntype SomeOptional = {\r\n [P in keyof Full]: Full[P]; // extends\r\n [P in 'field1' | 'field2']? : Full[P]; // override field1 and field2 to optional\r\n xxx: string; // and can add more fields.\r\n}\r\n\r\n//Suggestion 2: Identifer! to remove null and undefined\r\ntype SomeRequired = {\r\n [P in keyof SomeOptional]: SomeOptional[P]; // extends\r\n field1: SomeOptional[field1]!; // ! will remove null and undefined from a type\r\n}\r\n```\r\n\r\n**Benifit**\r\n1. It can resolve most problem with required and optional in current open issues. (like #15012, #16173, #13224, #12578, )\r\n2. More flexible to extend and override, in limited complexity.\r\n\r\n\r\nBTW, `function getProperty` in #12578 is a solution, but it cannot be used in declaration files.(`.d.ts`)","author":{"url":"https://github.com/k8w","@type":"Person","name":"k8w"},"datePublished":"2017-09-19T05:53:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/18567/TypeScript/issues/18567"}
| 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:5944ea4a-179d-9147-77b0-b133f1fda521 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C11A:179354:A555F6:DFA5E3:6A62EFE3 |
| html-safe-nonce | 79496d3f48d2b1cd5fd5219ae67c36a36578769b92b7955398fd3d0b89d1aca3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTFBOjE3OTM1NDpBNTU1RjY6REZBNUUzOjZBNjJFRkUzIiwidmlzaXRvcl9pZCI6IjYwMzkxMjg1Nzg5OTQyOTg2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9efbd39f3d6417f5369fc71a245e2c054118992d052169900436a32dabe9de9c |
| hovercard-subject-tag | issue:258704112 |
| 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/18567/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c1fcd8f19acf4f4e15f55309c2c89eb3cfe16eddfa118f1d61117a4d62e4744/microsoft/TypeScript/issues/18567 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c1fcd8f19acf4f4e15f55309c2c89eb3cfe16eddfa118f1d61117a4d62e4744/microsoft/TypeScript/issues/18567 |
| og:image:alt | TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx) 2.5.2 Situation There are lots of demand of more flexibility to Mapped Type. For example: Extend from a type and override some fields Turn o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | k8w |
| hostname | github.com |
| expected-hostname | github.com |
| None | b415018e190e73858133ddcaa36acce7b3f3572fe54dda84bd3b21a6ec714c30 |
| 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 | 22f98521e99f504294ab0812b66104d50eb75a70 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width