{"id":12161,"date":"2026-01-02T14:14:45","date_gmt":"2026-01-02T14:14:45","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=12161"},"modified":"2026-01-02T14:14:45","modified_gmt":"2026-01-02T14:14:45","slug":"pick-and-omit-in-typescript","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/pick-and-omit-in-typescript\/","title":{"rendered":"Pick and Omit in Typescript"},"content":{"rendered":"<p>Pick and Omit are used to pick fields from a type to create a new type or, in the case of Omit, returns a type with supplied fields omitted.<\/p>\n<p>For example, if we have a simple type such as this<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ntype Person = {\r\n  firstName: string\r\n  lastName: string\r\n  age: number\r\n}\r\n<\/pre>\n<p>We might wish to create a new type based upon the Person type but with only the first name. We can use Pick to pick the fields like this<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nfunction pickSample(person: Pick&lt;Person, &quot;firstName&quot;&gt;): string {\r\n  return `Hello, ${person.firstName}!`\r\n}\r\n<\/pre>\n<p>We can do the opposite using Omit, hence excluding fields<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nfunction omitSample(person: Omit&lt;Person, &quot;age&quot;&gt;): string {\r\n  return `Hello, ${person.firstName} ${person.lastName}`;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pick and Omit are used to pick fields from a type to create a new type or, in the case of Omit, returns a type with supplied fields omitted. For example, if we have a simple type such as this type Person = { firstName: string lastName: string age: number } We might wish to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[46],"tags":[],"class_list":["post-12161","post","type-post","status-publish","format-standard","hentry","category-typescript"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=12161"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12161\/revisions"}],"predecessor-version":[{"id":12163,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12161\/revisions\/12163"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=12161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=12161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=12161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}