[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"article-weekly-typescript-utility-types":44,"search-suggestions":549,"path-membership-weekly-typescript-utility-types":589,"related-weekly-typescript-utility-types":590,"code:ts:true:1nucqos":719,"code:ts:true:16kzzoz":720,"code:ts:true:2yx39h":721,"code:ts:true:1mlu74k":722,"code:ts:true:9i6av7":723,"code:ts:true:n633ah":724,"code:ts:true:1b5hmm5":725,"code:ts:true:1k0hvzq":726,"code:ts:true:ow615h":727,"code:ts:true:am7iy0":728,"code:ts:true:fajy2u":729,"code:ts:true:xrb3rr":730,"code:ts:true:1bq8f4l":731,"code:ts:true:237d3z":732,"code:ts:true:q57xjp":733,"code:ts:true:6b9j9c":734,"code:ts:true:10s6qiq":735,"comments-01a1df1b-1e04-73b8-9561-5b7b2459f738":736},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":53,"likeCount":19,"commentCount":19,"author":54,"vertical":59,"topic":60,"tags":63,"_count":75,"playground":77,"body":79,"bodyMd":495,"seo":496,"translationGroupId":498,"series":499,"podcastUrl":48,"verticalId":5,"thread":538,"assessments":540,"translations":545,"quiz":547},"01a1df1b-1e04-73b8-9561-5b7b2459f738","weekly-typescript-utility-types","TypeScript Utility Types: The Complete Guide",null,"Learn TypeScript utility types — Partial, Pick, Omit, Record, Exclude, ReturnType — and the mapped types behind them, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fweekly-typescript-utility-types.png",15,"2026-11-27T11:41:53.859Z",8,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},"typescript","TypeScript",[64,66,69,72],{"slug":61,"name":65,"color":48},"Typescript",{"slug":67,"name":68,"color":48},"javascript","Javascript",{"slug":70,"name":71,"color":48},"tutorial","Tutorial",{"slug":73,"name":74,"color":48},"webdev","Webdev",{"assessments":76},1,{"slug":46,"title":78},"TypeScript utility types — interactive playground",{"blocks":80,"version":76},[81,85,90,93,102,105,108,122,125,128,134,137,140,144,147,150,153,156,160,163,166,170,173,177,180,184,187,190,194,197,201,204,208,211,214,218,221,224,228,231,234,237,240,243,246,249,252,256,259,262,266,269,272,276,279,282,285,289,292,295,298,302,305,308,312,315,318,321,324,327,330,333,337,340,344,347,351,354,358,361,365,368,371,430,434,437,440,443,446,449,452,459,462,465,468,471,477,480,483,486,489],{"id":82,"html":83,"type":84},"b1","\u003Cp>You add a field to your \u003Ccode>User\u003C\u002Fcode> interface. Somewhere three files away, a hand-written \u003Ccode>UpdateUserInput\u003C\u002Fcode> type — built the week before by copying \u003Ccode>User\u003C\u002Fcode> and manually marking six fields optional — doesn&#39;t get the memo. It still compiles. It&#39;s just wrong, and nothing tells you until a form silently drops the new field at runtime.\u003C\u002Fp>","paragraph",{"id":86,"html":87,"text":88,"type":89,"level":31},"b2","What you&#39;ll learn","What you'll learn","heading",{"id":91,"html":92,"type":84},"b3","\u003Cp>By the end of this guide you&#39;ll be able to:\u003C\u002Fp>",{"id":94,"type":95,"items":96,"ordered":18},"b4","list",[97,98,99,100,101],"Explain what a utility type actually is under the hood — not a special compiler feature, just a mapped or conditional type someone wrote once","Use \u003Ccode>Partial\u003C\u002Fcode>, \u003Ccode>Required\u003C\u002Fcode>, \u003Ccode>Readonly\u003C\u002Fcode>, \u003Ccode>Pick\u003C\u002Fcode>, \u003Ccode>Omit\u003C\u002Fcode>, and \u003Ccode>Record\u003C\u002Fcode> correctly, including the shallow-ness that trips people up","Use \u003Ccode>Exclude\u003C\u002Fcode>, \u003Ccode>Extract\u003C\u002Fcode>, \u003Ccode>NonNullable\u003C\u002Fcode>, \u003Ccode>ReturnType\u003C\u002Fcode>, \u003Ccode>Parameters\u003C\u002Fcode>, and \u003Ccode>Awaited\u003C\u002Fcode> to derive types from other types instead of hand-writing them","Recognize why \u003Ccode>Omit\u003C\u002Fcode> silently drops fields on a union type, and fix it with a two-line distributive version","Decide when reaching for a built-in utility type is the right call, and when a hand-written type is clearer",{"id":103,"html":104,"type":84},"b5","\u003Cp>\u003Cstrong>Who this is for:\u003C\u002Fstrong> you&#39;ve written interfaces, functions, and generics in TypeScript, and you&#39;ve used \u003Ccode>Partial&lt;T&gt;\u003C\u002Fcode> or \u003Ccode>Omit&lt;T, K&gt;\u003C\u002Fcode> without being totally sure what they expand to.\u003C\u002Fp>",{"id":106,"html":107,"text":107,"type":89,"level":31},"b6","Contents",{"id":109,"type":95,"items":110,"ordered":18},"b7",[111,112,113,114,115,116,117,118,119,120,121],"\u003Ca href=\"#why-utility-types-exist\">Why utility types exist\u003C\u002Fa>","\u003Ca href=\"#the-mental-model-utility-types-are-just-mapped-and-conditional-types\">The mental model\u003C\u002Fa>","\u003Ca href=\"#stage-1-the-modifier-types-partial-required-readonly\">Stage 1: the modifier types — Partial, Required, Readonly\u003C\u002Fa>","\u003Ca href=\"#stage-2-the-key-selection-types-pick-omit-record\">Stage 2: the key-selection types — Pick, Omit, Record\u003C\u002Fa>","\u003Ca href=\"#stage-3-the-conditional-types-exclude-extract-nonnullable\">Stage 3: the conditional types — Exclude, Extract, NonNullable\u003C\u002Fa>","\u003Ca href=\"#stage-4-the-introspection-types-returntype-parameters-awaited\">Stage 4: the introspection types — ReturnType, Parameters, Awaited\u003C\u002Fa>","\u003Ca href=\"#edge-cases-and-gotchas\">Edge cases and gotchas\u003C\u002Fa>","\u003Ca href=\"#best-practices\">Best practices\u003C\u002Fa>","\u003Ca href=\"#faq\">FAQ\u003C\u002Fa>","\u003Ca href=\"#cheat-sheet\">Cheat sheet\u003C\u002Fa>","\u003Ca href=\"#key-takeaways\">Key takeaways\u003C\u002Fa>",{"id":123,"html":124,"text":124,"type":89,"level":31},"b8","Why utility types exist",{"id":126,"html":127,"type":84},"b9","\u003Cp>Here&#39;s the naïve version of the opening story, written out:\u003C\u002Fp>",{"id":129,"code":130,"type":131,"language":132,"highlight":133},"b10","interface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\n\u002F\u002F hand-written, copy-pasted from User the week before this field existed\ninterface UpdateUserInput {\n  name?: string;\n  email?: string;\n  role?: \"admin\" | \"member\";\n  \u002F\u002F id intentionally left off — you don't update the id\n  \u002F\u002F ...and whatever gets added to User next just won't show up here\n}","code","ts",[],{"id":135,"html":136,"type":84},"b11","\u003Cp>\u003Ccode>UpdateUserInput\u003C\u002Fcode> isn&#39;t connected to \u003Ccode>User\u003C\u002Fcode> in any way the compiler can see. It&#39;s a second, independent type that happens to look similar today. Add \u003Ccode>avatarUrl\u003C\u002Fcode> to \u003Ccode>User\u003C\u002Fcode> and \u003Ccode>UpdateUserInput\u003C\u002Fcode> has no idea — it keeps compiling, keeps passing review, and keeps being wrong.\u003C\u002Fp>",{"id":138,"html":139,"type":84},"b12","\u003Cp>The fix is to \u003Cstrong>derive\u003C\u002Fstrong> the new type from the old one instead of retyping it:\u003C\u002Fp>",{"id":141,"code":142,"type":131,"language":132,"highlight":143},"b13","type UpdateUserInput = Partial\u003COmit\u003CUser, \"id\">>;\n\u002F\u002F { name?: string; email?: string; role?: (\"admin\" | \"member\") | undefined }",[],{"id":145,"html":146,"type":84},"b14","\u003Cp>Now \u003Ccode>UpdateUserInput\u003C\u002Fcode> is a \u003Cem>computation\u003C\u002Fem> over \u003Ccode>User\u003C\u002Fcode>, not a copy of it. Add \u003Ccode>avatarUrl\u003C\u002Fcode> to \u003Ccode>User\u003C\u002Fcode> and \u003Ccode>UpdateUserInput\u003C\u002Fcode> picks it up automatically, still optional, still without \u003Ccode>id\u003C\u002Fcode>. \u003Ccode>Partial\u003C\u002Fcode> and \u003Ccode>Omit\u003C\u002Fcode> are the two utility types doing that work — and they ship with TypeScript&#39;s standard library, in \u003Ccode>lib.es5.d.ts\u003C\u002Fcode>, as plain type aliases you could have written yourself.\u003C\u002Fp>",{"id":148,"html":149,"text":149,"type":89,"level":31},"b15","The mental model: utility types are just mapped and conditional types",{"id":151,"html":152,"type":84},"b16","\u003Cp>\u003Cstrong>The mental model:\u003C\u002Fstrong> a utility type is not a compiler feature — it&#39;s an ordinary generic type alias, built from two tools you already have: a \u003Cstrong>mapped type\u003C\u002Fstrong> (loop over a type&#39;s keys and transform each property) and a \u003Cstrong>conditional type\u003C\u002Fstrong> (branch on whether one type is assignable to another). TypeScript ships about twenty of these pre-written so you don&#39;t retype them, but nothing stops you from writing your own.\u003C\u002Fp>",{"id":154,"html":155,"type":84},"b17","\u003Cp>Here&#39;s \u003Ccode>Partial&lt;T&gt;\u003C\u002Fcode> in full — this is close to its real definition in \u003Ccode>lib.es5.d.ts\u003C\u002Fcode>:\u003C\u002Fp>",{"id":157,"code":158,"type":131,"language":132,"highlight":159},"b18","type MyPartial\u003CT> = {\n  [K in keyof T]?: T[K];\n};",[],{"id":161,"html":162,"type":84},"b19","\u003Cp>Read it like a \u003Ccode>for...in\u003C\u002Fcode> loop over types: \u003Ccode>K in keyof T\u003C\u002Fcode> walks every key of \u003Ccode>T\u003C\u002Fcode>; \u003Ccode>?:\u003C\u002Fcode> adds the optional modifier to each one; \u003Ccode>T[K]\u003C\u002Fcode> keeps that property&#39;s original type. That&#39;s the entire mechanism. \u003Ccode>Required&lt;T&gt;\u003C\u002Fcode> is the same loop with \u003Ccode>-?\u003C\u002Fcode> (remove the optional modifier) instead of \u003Ccode>?\u003C\u002Fcode>. \u003Ccode>Readonly&lt;T&gt;\u003C\u002Fcode> is the same loop with \u003Ccode>readonly\u003C\u002Fcode> added. Three &quot;different&quot; utility types, one template, one character changed each time.\u003C\u002Fp>",{"id":164,"html":165,"type":84},"b20","\u003Cp>\u003Ccode>Pick\u003C\u002Fcode> and \u003Ccode>Omit\u003C\u002Fcode> use the same mapped-type loop, but over a narrower or computed set of keys instead of all of \u003Ccode>keyof T\u003C\u002Fcode>:\u003C\u002Fp>",{"id":167,"code":168,"type":131,"language":132,"highlight":169},"b21","type MyPick\u003CT, K extends keyof T> = {\n  [P in K]: T[P];\n};\n\ntype MyOmit\u003CT, K extends keyof any> = MyPick\u003CT, Exclude\u003Ckeyof T, K>>;",[],{"id":171,"html":172,"type":84},"b22","\u003Cp>\u003Ccode>Omit\u003C\u002Fcode> isn&#39;t its own primitive — it&#39;s \u003Ccode>Pick\u003C\u002Fcode> over &quot;every key except these,&quot; and &quot;every key except these&quot; is \u003Ccode>Exclude\u003C\u002Fcode>, a \u003Cstrong>conditional type\u003C\u002Fstrong>:\u003C\u002Fp>",{"id":174,"code":175,"type":131,"language":132,"highlight":176},"b23","type MyExclude\u003CT, U> = T extends U ? never : T;",[],{"id":178,"html":179,"type":84},"b24","\u003Cp>Read that as: for each member of \u003Ccode>T\u003C\u002Fcode>, if it&#39;s assignable to \u003Ccode>U\u003C\u002Fcode>, replace it with \u003Ccode>never\u003C\u002Fcode> (which then vanishes from a union); otherwise keep it. This single four-word conditional is the engine behind \u003Ccode>Exclude\u003C\u002Fcode>, \u003Ccode>Extract\u003C\u002Fcode>, and — as you&#39;ll see in the edge cases section — the reason \u003Ccode>Omit\u003C\u002Fcode> behaves unexpectedly on union types.\u003C\u002Fp>",{"id":181,"html":182,"type":183},"b25","\u003Cp>\u003Cstrong>Key concept:\u003C\u002Fstrong> once you can read \u003Ccode>[K in keyof T]\u003C\u002Fcode> as &quot;loop over keys&quot; and \u003Ccode>T extends U ? X : Y\u003C\u002Fcode> as &quot;branch on assignability,&quot; every utility type in the standard library is legible on sight. You&#39;re not memorizing twenty names — you&#39;re applying two patterns.\u003C\u002Fp>\n","quote",{"id":185,"html":186,"text":186,"type":89,"level":31},"b26","Stage 1: the modifier types — Partial, Required, Readonly",{"id":188,"html":189,"type":84},"b27","\u003Cp>These three change \u003Cem>which modifiers\u003C\u002Fem> apply to every property, without touching which properties exist.\u003C\u002Fp>",{"id":191,"code":192,"type":131,"language":132,"highlight":193},"b28","interface Config {\n  host: string;\n  port: number;\n  debug?: boolean;\n}\n\ntype PartialConfig = Partial\u003CConfig>;\n\u002F\u002F { host?: string; port?: number; debug?: boolean }\n\ntype RequiredConfig = Required\u003CConfig>;\n\u002F\u002F { host: string; port: number; debug: boolean }  — debug's \"?\" is gone\n\ntype ReadonlyConfig = Readonly\u003CConfig>;\n\u002F\u002F { readonly host: string; readonly port: number; readonly debug?: boolean }",[],{"id":195,"html":196,"type":84},"b29","\u003Cp>\u003Ccode>Partial\u003C\u002Fcode> is the one you reach for constantly: update payloads, form state before every field is filled in, default-merging (\u003Ccode>{ ...defaults, ...overrides }\u003C\u002Fcode> where \u003Ccode>overrides: Partial&lt;Config&gt;\u003C\u002Fcode>). \u003Ccode>Required\u003C\u002Fcode> is its mirror — useful for asserting that, after validation, every optional field has in fact been filled:\u003C\u002Fp>",{"id":198,"code":199,"type":131,"language":132,"highlight":200},"b30","function startServer(config: Required\u003CConfig>) {\n  \u002F\u002F debug is guaranteed defined here — the compiler enforces it at the call site\n}",[],{"id":202,"html":203,"type":84},"b31","\u003Cp>\u003Ccode>Readonly\u003C\u002Fcode> prevents reassignment of top-level properties:\u003C\u002Fp>",{"id":205,"code":206,"type":131,"language":132,"highlight":207},"b32","const c: Readonly\u003CConfig> = { host: \"localhost\", port: 3000 };\nc.port = 4000; \u002F\u002F Error: Cannot assign to 'port' because it is a read-only property.",[],{"id":209,"html":210,"text":210,"type":89,"level":31},"b33","Stage 2: the key-selection types — Pick, Omit, Record",{"id":212,"html":213,"type":84},"b34","\u003Cp>These change \u003Cem>which properties exist\u003C\u002Fem>, keeping their original modifiers and types.\u003C\u002Fp>",{"id":215,"code":216,"type":131,"language":132,"highlight":217},"b35","interface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\ntype PublicUser = Pick\u003CUser, \"id\" | \"name\">;\n\u002F\u002F { id: string; name: string }\n\ntype UserWithoutId = Omit\u003CUser, \"id\">;\n\u002F\u002F { name: string; email: string; role: \"admin\" | \"member\" }",[],{"id":219,"html":220,"type":84},"b36","\u003Cp>\u003Ccode>Pick\u003C\u002Fcode> says &quot;keep only these keys&quot;; \u003Ccode>Omit\u003C\u002Fcode> says &quot;keep everything except these keys.&quot; Use \u003Ccode>Pick\u003C\u002Fcode> when the kept set is small and stable (a public-facing subset); use \u003Ccode>Omit\u003C\u002Fcode> when you&#39;re removing one or two fields from an otherwise-large shape and don&#39;t want to re-list everything you&#39;re keeping.\u003C\u002Fp>",{"id":222,"html":223,"type":84},"b37","\u003Cp>\u003Ccode>Record&lt;K, T&gt;\u003C\u002Fcode> builds an object type from a set of keys and a single value type — useful for lookup tables and maps keyed by a known union:\u003C\u002Fp>",{"id":225,"code":226,"type":131,"language":132,"highlight":227},"b38","type Role = \"admin\" | \"member\" | \"guest\";\n\nconst roleLabels: Record\u003CRole, string> = {\n  admin: \"Administrator\",\n  member: \"Member\",\n  guest: \"Guest\",\n};\n\u002F\u002F omit one key, e.g. \"guest\", and TypeScript errors: property is missing",[],{"id":229,"html":230,"type":84},"b39","\u003Cp>That last line is \u003Ccode>Record\u003C\u002Fcode>&#39;s real value over a plain index signature (\u003Ccode>{ [key: string]: string }\u003C\u002Fcode>): because the key type is a specific union, TypeScript checks that every member of the union has an entry, and rejects keys outside the union entirely.\u003C\u002Fp>",{"id":232,"html":233,"type":84},"b40","\u003C!-- playground:start -->",{"id":235,"html":236,"text":236,"type":89,"level":31},"b41","🎮 Try it yourself",{"id":238,"html":239,"type":84},"b42","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-utility-types\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":241,"html":242,"type":84},"b43","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":244,"html":245,"type":84},"b44","\u003C!-- playground:end -->",{"id":247,"html":248,"text":248,"type":89,"level":31},"b45","Stage 3: the conditional types — Exclude, Extract, NonNullable",{"id":250,"html":251,"type":84},"b46","\u003Cp>These operate on \u003Cstrong>unions\u003C\u002Fstrong>, not object shapes — think of them as set operations over the members of a union type.\u003C\u002Fp>",{"id":253,"code":254,"type":131,"language":132,"highlight":255},"b47","type Status = \"idle\" | \"loading\" | \"success\" | \"error\";\n\ntype NotIdle = Exclude\u003CStatus, \"idle\">;\n\u002F\u002F \"loading\" | \"success\" | \"error\"\n\ntype Settled = Extract\u003CStatus, \"success\" | \"error\">;\n\u002F\u002F \"success\" | \"error\"\n\ntype MaybeUser = User | null | undefined;\ntype DefiniteUser = NonNullable\u003CMaybeUser>;\n\u002F\u002F User",[],{"id":257,"html":258,"type":84},"b48","\u003Cp>\u003Ccode>Exclude&lt;T, U&gt;\u003C\u002Fcode> keeps the members of \u003Ccode>T\u003C\u002Fcode> that are \u003Cstrong>not\u003C\u002Fstrong> assignable to \u003Ccode>U\u003C\u002Fcode>; \u003Ccode>Extract&lt;T, U&gt;\u003C\u002Fcode> keeps the members that \u003Cstrong>are\u003C\u002Fstrong>. They&#39;re complements of each other over the same two inputs. \u003Ccode>NonNullable&lt;T&gt;\u003C\u002Fcode> strips \u003Ccode>null\u003C\u002Fcode> and \u003Ccode>undefined\u003C\u002Fcode> from \u003Ccode>T\u003C\u002Fcode> — it used to be defined as \u003Ccode>Exclude&lt;T, null | undefined&gt;\u003C\u002Fcode>, but since TypeScript 4.8 it&#39;s \u003Ccode>T &amp; {}\u003C\u002Fcode> instead (intersecting with the empty object type cancels \u003Ccode>null\u003C\u002Fcode> and \u003Ccode>undefined\u003C\u002Fcode> out, and unlike the old conditional type, the intersection form simplifies cleanly when \u003Ccode>T\u003C\u002Fcode> is itself generic).\u003C\u002Fp>",{"id":260,"html":261,"type":84},"b49","\u003Cp>A real use: narrowing a discriminated union after a check that a plain \u003Ccode>if\u003C\u002Fcode> can&#39;t express as a type:\u003C\u002Fp>",{"id":263,"code":264,"type":131,"language":132,"highlight":265},"b50","function isSettled(status: Status): status is Extract\u003CStatus, \"success\" | \"error\"> {\n  return status === \"success\" || status === \"error\";\n}",[],{"id":267,"html":268,"text":268,"type":89,"level":31},"b51","Stage 4: the introspection types — ReturnType, Parameters, Awaited",{"id":270,"html":271,"type":84},"b52","\u003Cp>These pull a type \u003Cstrong>out of a function signature or a Promise\u003C\u002Fstrong>, instead of transforming an object shape.\u003C\u002Fp>",{"id":273,"code":274,"type":131,"language":132,"highlight":275},"b53","function createUser(name: string, role: \"admin\" | \"member\") {\n  return { id: crypto.randomUUID(), name, role };\n}\n\ntype NewUser = ReturnType\u003Ctypeof createUser>;\n\u002F\u002F { id: string; name: string; role: \"admin\" | \"member\" }\n\ntype CreateUserArgs = Parameters\u003Ctypeof createUser>;\n\u002F\u002F [name: string, role: \"admin\" | \"member\"]\n\nasync function fetchUser(): Promise\u003CUser> {\n  \u002F* ... *\u002F\n  return {} as User;\n}\n\ntype FetchedUser = Awaited\u003CReturnType\u003Ctypeof fetchUser>>;\n\u002F\u002F User — not Promise\u003CUser>",[],{"id":277,"html":278,"type":84},"b54","\u003Cp>These three are the way to keep a type in sync with a function&#39;s \u003Cem>implementation\u003C\u002Fem> instead of a parallel hand-written declaration. \u003Ccode>typeof createUser\u003C\u002Fcode> gets you the function&#39;s type; \u003Ccode>ReturnType\u003C\u002Fcode> and \u003Ccode>Parameters\u003C\u002Fcode> pull pieces back out of it. \u003Ccode>Awaited&lt;T&gt;\u003C\u002Fcode> recursively unwraps nested promises (\u003Ccode>Promise&lt;Promise&lt;User&gt;&gt;\u003C\u002Fcode> still resolves to \u003Ccode>User\u003C\u002Fcode>), which is what makes \u003Ccode>Awaited&lt;ReturnType&lt;typeof fetchUser&gt;&gt;\u003C\u002Fcode> correct instead of leaving you with a dangling \u003Ccode>Promise&lt;User&gt;\u003C\u002Fcode>.\u003C\u002Fp>",{"id":280,"html":281,"text":281,"type":89,"level":31},"b55","Edge cases and gotchas",{"id":283,"html":284,"type":84},"b56","\u003Cp>\u003Cstrong>Every built-in here is shallow.\u003C\u002Fstrong> \u003Ccode>Partial&lt;T&gt;\u003C\u002Fcode>, \u003Ccode>Required&lt;T&gt;\u003C\u002Fcode>, and \u003Ccode>Readonly&lt;T&gt;\u003C\u002Fcode> only touch \u003Ccode>T\u003C\u002Fcode>&#39;s own top-level properties:\u003C\u002Fp>",{"id":286,"code":287,"type":131,"language":132,"highlight":288},"b57","interface Profile {\n  user: { name: string; email: string };\n}\n\ntype PartialProfile = Partial\u003CProfile>;\n\u002F\u002F { user?: { name: string; email: string } }\n\u002F\u002F user.name and user.email are still required — Partial didn't recurse\nconst p: PartialProfile = { user: { name: \"Ada\" } }; \u002F\u002F Error: email is missing",[],{"id":290,"html":291,"type":84},"b58","\u003Cp>If you need every nested field optional too, you need a recursive mapped type (often called \u003Ccode>DeepPartial\u003C\u002Fcode>) — it isn&#39;t in the standard library because &quot;how deep&quot; and &quot;should arrays recurse too&quot; are decisions a one-size-fits-all utility can&#39;t make for you.\u003C\u002Fp>",{"id":293,"html":294,"type":84},"b59","\u003Cp>\u003Cstrong>\u003Ccode>Readonly\u003C\u002Fcode> is compile-time only.\u003C\u002Fstrong> Nothing prevents \u003Ccode>Object.freeze\u003C\u002Fcode>-style mutation at runtime through an untyped reference, a cast, or library code that doesn&#39;t know about your type. \u003Ccode>Readonly&lt;T&gt;\u003C\u002Fcode> stops \u003Cem>your\u003C\u002Fem> code from writing through \u003Cem>that\u003C\u002Fem> reference; it is not a runtime guarantee.\u003C\u002Fp>",{"id":296,"html":297,"type":84},"b60","\u003Cp>\u003Cstrong>\u003Ccode>Omit\u003C\u002Fcode> on a union type silently drops fields it shouldn&#39;t.\u003C\u002Fstrong> This is the gotcha worth remembering. Recall \u003Ccode>Omit&lt;T, K&gt; = Pick&lt;T, Exclude&lt;keyof T, K&gt;&gt;\u003C\u002Fcode>. The bug is in what \u003Ccode>keyof\u003C\u002Fcode> means for a union:\u003C\u002Fp>",{"id":299,"code":300,"type":131,"language":132,"highlight":301},"b61","interface Circle { kind: \"circle\"; radius: number }\ninterface Square { kind: \"square\"; side: number }\ntype Shape = Circle | Square;\n\ntype ShapeWithoutKind = Omit\u003CShape, \"kind\">;\n\u002F\u002F You'd expect: { radius: number } | { side: number }\n\u002F\u002F You actually get: {}",[],{"id":303,"html":304,"type":84},"b62","\u003Cp>\u003Ccode>keyof (Circle | Square)\u003C\u002Fcode> is only the keys common to \u003Cem>every\u003C\u002Fem> member — here, just \u003Ccode>&quot;kind&quot;\u003C\u002Fcode> — because accessing a property on a union value only type-checks for properties every branch has. So \u003Ccode>Exclude&lt;keyof Shape, &quot;kind&quot;&gt;\u003C\u002Fcode> excludes the only common key and leaves \u003Ccode>never\u003C\u002Fcode>, and \u003Ccode>Pick&lt;Shape, never&gt;\u003C\u002Fcode> is \u003Ccode>{}\u003C\u002Fcode> for both branches. \u003Ccode>radius\u003C\u002Fcode> and \u003Ccode>side\u003C\u002Fcode> were never in the computation to begin with — they&#39;re silently gone, and \u003Ccode>ShapeWithoutKind\u003C\u002Fcode> is \u003Ccode>{}\u003C\u002Fcode>, not an error.\u003C\u002Fp>",{"id":306,"html":307,"type":84},"b63","\u003Cp>The fix is a \u003Cstrong>distributive\u003C\u002Fstrong> version that applies \u003Ccode>Omit\u003C\u002Fcode> to each union member separately before they&#39;re merged back into a union:\u003C\u002Fp>",{"id":309,"code":310,"type":131,"language":132,"highlight":311},"b64","type DistributiveOmit\u003CT, K extends PropertyKey> = T extends unknown\n  ? Omit\u003CT, K>\n  : never;\n\ntype ShapeWithoutKind = DistributiveOmit\u003CShape, \"kind\">;\n\u002F\u002F { radius: number } | { side: number } — correct",[],{"id":313,"html":314,"type":84},"b65","\u003Cp>The \u003Ccode>T extends unknown ? ... : never\u003C\u002Fcode> isn&#39;t a real check (every type extends \u003Ccode>unknown\u003C\u002Fcode>) — its only job is to make the conditional \u003Cstrong>distribute\u003C\u002Fstrong> over \u003Ccode>T\u003C\u002Fcode> when \u003Ccode>T\u003C\u002Fcode> is a union, running \u003Ccode>Omit\u003C\u002Fcode> once per branch instead of once on the merged type. This is the single most-cited TypeScript utility-type gotcha for a reason: it compiles cleanly and returns a plausible-looking empty object, so it tends to surface as a runtime bug, not a type error.\u003C\u002Fp>",{"id":316,"html":317,"text":317,"type":89,"level":31},"b66","Best practices",{"id":319,"html":320,"type":84},"b67","\u003Cp>\u003Cstrong>Reach for a built-in utility type when\u003C\u002Fstrong> you&#39;re deriving a type from one that already exists and is the source of truth — an API response shape, a Prisma\u002Fdatabase model, a component&#39;s prop type. The derived type should update automatically when the source changes; that&#39;s the entire point.\u003C\u002Fp>",{"id":322,"html":323,"type":84},"b68","\u003Cp>\u003Cstrong>Avoid them when\u003C\u002Fstrong> the &quot;derived&quot; type and the source type are only accidentally similar today and will diverge in meaning tomorrow. A \u003Ccode>LoginFormValues\u003C\u002Fcode> type that happens to share two field names with \u003Ccode>User\u003C\u002Fcode> isn&#39;t a \u003Ccode>Pick&lt;User, ...&gt;\u003C\u002Fcode> — it&#39;s its own type that should be declared as its own type.\u003C\u002Fp>",{"id":325,"html":326,"type":84},"b69","\u003Cp>\u003Cstrong>Prefer \u003Ccode>Pick\u003C\u002Fcode> over \u003Ccode>Omit\u003C\u002Fcode>\u003C\u002Fstrong> when the kept set is small (2–3 fields) and stable — it reads as an explicit allowlist and doesn&#39;t silently include a field someone adds to the source type later without you noticing. \u003Cstrong>Prefer \u003Ccode>Omit\u003C\u002Fcode>\u003C\u002Fstrong> when you&#39;re removing one or two fields from an otherwise-large, evolving shape.\u003C\u002Fp>",{"id":328,"html":329,"type":84},"b70","\u003Cp>\u003Cstrong>Reach for \u003Ccode>DistributiveOmit\u003C\u002Fcode> deliberately\u003C\u002Fstrong>, not by default — write \u003Ccode>Omit\u003C\u002Fcode> first, and only swap in the distributive version once you&#39;ve confirmed the source type is (or might become) a union. Reaching for it reflexively everywhere adds a layer of indirection most object shapes never need.\u003C\u002Fp>",{"id":331,"html":332,"text":332,"type":89,"level":31},"b71","FAQ",{"id":334,"html":335,"text":336,"type":89,"level":43},"b72","Does \u003Ccode>Partial&lt;T&gt;\u003C\u002Fcode> make nested object properties optional too?","Does Partial\u003CT> make nested object properties optional too?",{"id":338,"html":339,"type":84},"b73","\u003Cp>No. \u003Ccode>Partial\u003C\u002Fcode>, \u003Ccode>Required\u003C\u002Fcode>, and \u003Ccode>Readonly\u003C\u002Fcode> are shallow — they only transform \u003Ccode>T\u003C\u002Fcode>&#39;s own top-level properties. A property whose type is itself an object keeps that object&#39;s original required\u002Foptional fields untouched. Use a hand-written recursive mapped type if you need every nested level.\u003C\u002Fp>",{"id":341,"html":342,"text":343,"type":89,"level":43},"b74","Why does \u003Ccode>Omit\u003C\u002Fcode> return \u003Ccode>{}\u003C\u002Fcode> on a union type instead of erroring?","Why does Omit return {} on a union type instead of erroring?",{"id":345,"html":346,"type":84},"b75","\u003Cp>Because \u003Ccode>Omit&lt;T, K&gt;\u003C\u002Fcode> is implemented as \u003Ccode>Pick&lt;T, Exclude&lt;keyof T, K&gt;&gt;\u003C\u002Fcode>, and \u003Ccode>keyof\u003C\u002Fcode> on a union type only yields the keys common to every member. If the only common key is the one you&#39;re omitting, the key set to keep becomes \u003Ccode>never\u003C\u002Fcode>, and \u003Ccode>Pick&lt;T, never&gt;\u003C\u002Fcode> is \u003Ccode>{}\u003C\u002Fcode>. Use a distributive version (\u003Ccode>T extends unknown ? Omit&lt;T, K&gt; : never\u003C\u002Fcode>) to get the per-branch result you expect. See &quot;Edge cases and gotchas&quot; above for the full example.\u003C\u002Fp>",{"id":348,"html":349,"text":350,"type":89,"level":43},"b76","Can I combine utility types, like \u003Ccode>Partial&lt;Pick&lt;T, K&gt;&gt;\u003C\u002Fcode>?","Can I combine utility types, like Partial\u003CPick\u003CT, K>>?",{"id":352,"html":353,"type":84},"b77","\u003Cp>Yes — they&#39;re ordinary generic types, so they compose exactly like function calls. \u003Ccode>Partial&lt;Pick&lt;User, &quot;name&quot; | &quot;email&quot;&gt;&gt;\u003C\u002Fcode> first narrows to two fields, then makes both optional. Order matters: \u003Ccode>Pick&lt;Partial&lt;User&gt;, &quot;name&quot;&gt;\u003C\u002Fcode> makes everything optional first, then keeps only \u003Ccode>name\u003C\u002Fcode> (still optional) — a different, usually less useful, result for this case.\u003C\u002Fp>",{"id":355,"html":356,"text":357,"type":89,"level":43},"b78","What&#39;s the difference between \u003Ccode>Record&lt;string, T&gt;\u003C\u002Fcode> and an index signature?","What's the difference between Record\u003Cstring, T> and an index signature?",{"id":359,"html":360,"type":84},"b79","\u003Cp>For a plain \u003Ccode>string\u003C\u002Fcode> key type they behave almost identically — \u003Ccode>Record&lt;string, T&gt;\u003C\u002Fcode> is defined using an index signature internally. The difference matters when the key type is a specific union: \u003Ccode>Record&lt;Role, string&gt;\u003C\u002Fcode> checks that every member of \u003Ccode>Role\u003C\u002Fcode> has an entry and rejects extra keys, while \u003Ccode>{ [key: string]: string }\u003C\u002Fcode> accepts any string key and enforces nothing about which keys must be present.\u003C\u002Fp>",{"id":362,"html":363,"text":364,"type":89,"level":43},"b80","Does TypeScript have a built-in \u003Ccode>DeepPartial\u003C\u002Fcode> or \u003Ccode>DeepReadonly\u003C\u002Fcode>?","Does TypeScript have a built-in DeepPartial or DeepReadonly?",{"id":366,"html":367,"type":84},"b81","\u003Cp>No. The standard library intentionally ships only shallow versions, because &quot;how deep,&quot; &quot;should this recurse into arrays and \u003Ccode>Map\u003C\u002Fcode>\u002F\u003Ccode>Set\u003C\u002Fcode>,&quot; and &quot;should functions be left alone&quot; are decisions that vary by use case. Write your own recursive mapped type, or use a small, well-tested library version if you need one across a codebase.\u003C\u002Fp>",{"id":369,"html":370,"text":370,"type":89,"level":31},"b82","Cheat sheet",{"id":372,"head":373,"rows":377,"type":429},"b83",[374,375,376],"Task","Code","Notes",[378,382,386,390,394,398,402,406,410,414,418,422,425],[379,380,381],"Make every property optional","\u003Ccode>Partial&lt;T&gt;\u003C\u002Fcode>","Shallow — nested objects keep their original required fields",[383,384,385],"Make every property required","\u003Ccode>Required&lt;T&gt;\u003C\u002Fcode>","Removes the \u003Ccode>?\u003C\u002Fcode> modifier everywhere, shallow",[387,388,389],"Make every property readonly","\u003Ccode>Readonly&lt;T&gt;\u003C\u002Fcode>","Compile-time only, shallow, no runtime freeze",[391,392,393],"Keep only some properties","\u003Ccode>Pick&lt;T, &quot;a&quot; | &quot;b&quot;&gt;\u003C\u002Fcode>","Explicit allowlist; new fields on \u003Ccode>T\u003C\u002Fcode> are excluded by default",[395,396,397],"Remove some properties","\u003Ccode>Omit&lt;T, &quot;a&quot; | &quot;b&quot;&gt;\u003C\u002Fcode>","Based on \u003Ccode>Pick\u003C\u002Fcode> + \u003Ccode>Exclude\u003C\u002Fcode> — see the union gotcha before using on a union",[399,400,401],"Omit on a union, correctly","\u003Ccode>T extends unknown ? Omit&lt;T, K&gt; : never\u003C\u002Fcode>","Forces per-branch distribution",[403,404,405],"Build a lookup object type","\u003Ccode>Record&lt;K, T&gt;\u003C\u002Fcode>","\u003Ccode>K\u003C\u002Fcode> a union enforces every key is present and no extra keys",[407,408,409],"Keep union members assignable to \u003Ccode>U\u003C\u002Fcode>","\u003Ccode>Extract&lt;T, U&gt;\u003C\u002Fcode>","",[411,412,413],"Remove union members assignable to \u003Ccode>U\u003C\u002Fcode>","\u003Ccode>Exclude&lt;T, U&gt;\u003C\u002Fcode>","Complement of \u003Ccode>Extract\u003C\u002Fcode>",[415,416,417],"Strip \u003Ccode>null\u003C\u002Fcode>\u002F\u003Ccode>undefined\u003C\u002Fcode> from a type","\u003Ccode>NonNullable&lt;T&gt;\u003C\u002Fcode>","\u003Ccode>T &amp; {}\u003C\u002Fcode> since TS 4.8 (was \u003Ccode>Exclude&lt;T, null | undefined&gt;\u003C\u002Fcode> before that)",[419,420,421],"Get a function&#39;s return type","\u003Ccode>ReturnType&lt;typeof fn&gt;\u003C\u002Fcode>","Use \u003Ccode>typeof fn\u003C\u002Fcode>, not \u003Ccode>fn\u003C\u002Fcode>, to reference the function&#39;s type",[423,424,409],"Get a function&#39;s parameter tuple","\u003Ccode>Parameters&lt;typeof fn&gt;\u003C\u002Fcode>",[426,427,428],"Unwrap a (possibly nested) Promise","\u003Ccode>Awaited&lt;T&gt;\u003C\u002Fcode>","\u003Ccode>Awaited&lt;ReturnType&lt;typeof asyncFn&gt;&gt;\u003C\u002Fcode> gives the resolved value&#39;s type","table",{"id":431,"code":432,"type":131,"language":132,"highlight":433},"b84","\u002F\u002F the whole pattern, copy-paste ready\ninterface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\n\u002F\u002F derive, don't retype\ntype PublicUser = Pick\u003CUser, \"id\" | \"name\">;\ntype UpdateUserInput = Partial\u003COmit\u003CUser, \"id\">>;\ntype UserMap = Record\u003Cstring, User>;\n\ntype DistributiveOmit\u003CT, K extends PropertyKey> = T extends unknown\n  ? Omit\u003CT, K>\n  : never;",[],{"id":435,"html":436,"type":84},"b85","\u003C!-- quiz:start -->",{"id":438,"html":439,"text":439,"type":89,"level":31},"b86","🧠 Test yourself",{"id":441,"html":442,"type":84},"b87","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-utility-types\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":444,"html":445,"type":84},"b88","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":447,"html":448,"type":84},"b89","\u003C!-- quiz:end -->",{"id":450,"html":451,"text":451,"type":89,"level":31},"b90","Key takeaways",{"id":453,"type":95,"items":454,"ordered":18},"b91",[455,456,457,458],"A utility type is a mapped type (\u003Ccode>[K in keyof T]\u003C\u002Fcode>) or a conditional type (\u003Ccode>T extends U ? X : Y\u003C\u002Fcode>) someone already wrote — not a special compiler feature. You can write your own.","\u003Ccode>Partial\u003C\u002Fcode>, \u003Ccode>Required\u003C\u002Fcode>, and \u003Ccode>Readonly\u003C\u002Fcode> change modifiers; \u003Ccode>Pick\u003C\u002Fcode>, \u003Ccode>Omit\u003C\u002Fcode>, and \u003Ccode>Record\u003C\u002Fcode> change which keys exist; \u003Ccode>Exclude\u003C\u002Fcode>\u002F\u003Ccode>Extract\u003C\u002Fcode>\u002F\u003Ccode>NonNullable\u003C\u002Fcode> operate on unions; \u003Ccode>ReturnType\u003C\u002Fcode>\u002F\u003Ccode>Parameters\u003C\u002Fcode>\u002F\u003Ccode>Awaited\u003C\u002Fcode> pull types out of function signatures.","Every built-in here is shallow — nested objects are untouched unless you write a recursive version yourself.","\u003Ccode>Omit\u003C\u002Fcode> on a union type can silently collapse to \u003Ccode>{}\u003C\u002Fcode>. If the source type might be a union, use a distributive \u003Ccode>Omit\u003C\u002Fcode>.",{"id":460,"html":461,"type":84},"b92","\u003Cp>That \u003Ccode>UpdateUserInput\u003C\u002Fcode> from the opening — the one that quietly missed a field — was never going to catch up to \u003Ccode>User\u003C\u002Fcode> by being retyped more carefully. It needed to stop being its own type and become a computation over \u003Ccode>User\u003C\u002Fcode> instead. That&#39;s what every utility type in this guide is: not a list of twenty names to memorize, but two small tools — loop over keys, branch on assignability — applied again and again.\u003C\u002Fp>",{"id":463,"html":464,"type":84},"b93","\u003Cp>Which one bit you first: the shallow \u003Ccode>Partial\u003C\u002Fcode>, or the union \u003Ccode>Omit\u003C\u002Fcode>? Tell me in the comments — I&#39;ll compile the most common one into next week&#39;s &quot;gotchas&quot; post.\u003C\u002Fp>",{"id":466,"html":467,"type":84},"b94","\u003C!-- related:start -->",{"id":469,"html":470,"text":470,"type":89,"level":31},"b95","📚 Read next",{"id":472,"type":95,"items":473,"ordered":18},"b96",[474,475,476],"\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-generics\">TypeScript Generics: The Complete Guide (with Cheat Sheet)\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-web-workers\">Web Workers in JavaScript: The Complete Guide\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-javascript-proxy-reflect\">JavaScript Proxy and Reflect: The Complete Guide\u003C\u002Fa>",{"id":478,"html":479,"type":84},"b97","\u003C!-- related:end -->",{"id":481,"type":482},"b98","divider",{"id":484,"html":485,"type":84},"b99","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":487,"html":488,"type":84},"b100","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":490,"type":95,"items":491,"ordered":18},"b101",[492,493,494],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","You add a field to your `User` interface. Somewhere three files away, a hand-written `UpdateUserInput` type — built the week before by copying `User` and manually marking six fields optional — doesn't get the memo. It still compiles. It's just wrong, and nothing tells you until a form silently drops the new field at runtime.\n\n## What you'll learn\n\nBy the end of this guide you'll be able to:\n\n- Explain what a utility type actually is under the hood — not a special compiler feature, just a mapped or conditional type someone wrote once\n- Use `Partial`, `Required`, `Readonly`, `Pick`, `Omit`, and `Record` correctly, including the shallow-ness that trips people up\n- Use `Exclude`, `Extract`, `NonNullable`, `ReturnType`, `Parameters`, and `Awaited` to derive types from other types instead of hand-writing them\n- Recognize why `Omit` silently drops fields on a union type, and fix it with a two-line distributive version\n- Decide when reaching for a built-in utility type is the right call, and when a hand-written type is clearer\n\n**Who this is for:** you've written interfaces, functions, and generics in TypeScript, and you've used `Partial\u003CT>` or `Omit\u003CT, K>` without being totally sure what they expand to.\n\n## Contents\n\n- [Why utility types exist](#why-utility-types-exist)\n- [The mental model](#the-mental-model-utility-types-are-just-mapped-and-conditional-types)\n- [Stage 1: the modifier types — Partial, Required, Readonly](#stage-1-the-modifier-types-partial-required-readonly)\n- [Stage 2: the key-selection types — Pick, Omit, Record](#stage-2-the-key-selection-types-pick-omit-record)\n- [Stage 3: the conditional types — Exclude, Extract, NonNullable](#stage-3-the-conditional-types-exclude-extract-nonnullable)\n- [Stage 4: the introspection types — ReturnType, Parameters, Awaited](#stage-4-the-introspection-types-returntype-parameters-awaited)\n- [Edge cases and gotchas](#edge-cases-and-gotchas)\n- [Best practices](#best-practices)\n- [FAQ](#faq)\n- [Cheat sheet](#cheat-sheet)\n- [Key takeaways](#key-takeaways)\n\n## Why utility types exist\n\nHere's the naïve version of the opening story, written out:\n\n```ts\ninterface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\n\u002F\u002F hand-written, copy-pasted from User the week before this field existed\ninterface UpdateUserInput {\n  name?: string;\n  email?: string;\n  role?: \"admin\" | \"member\";\n  \u002F\u002F id intentionally left off — you don't update the id\n  \u002F\u002F ...and whatever gets added to User next just won't show up here\n}\n```\n\n`UpdateUserInput` isn't connected to `User` in any way the compiler can see. It's a second, independent type that happens to look similar today. Add `avatarUrl` to `User` and `UpdateUserInput` has no idea — it keeps compiling, keeps passing review, and keeps being wrong.\n\nThe fix is to **derive** the new type from the old one instead of retyping it:\n\n```ts\ntype UpdateUserInput = Partial\u003COmit\u003CUser, \"id\">>;\n\u002F\u002F { name?: string; email?: string; role?: (\"admin\" | \"member\") | undefined }\n```\n\nNow `UpdateUserInput` is a *computation* over `User`, not a copy of it. Add `avatarUrl` to `User` and `UpdateUserInput` picks it up automatically, still optional, still without `id`. `Partial` and `Omit` are the two utility types doing that work — and they ship with TypeScript's standard library, in `lib.es5.d.ts`, as plain type aliases you could have written yourself.\n\n## The mental model: utility types are just mapped and conditional types\n\n**The mental model:** a utility type is not a compiler feature — it's an ordinary generic type alias, built from two tools you already have: a **mapped type** (loop over a type's keys and transform each property) and a **conditional type** (branch on whether one type is assignable to another). TypeScript ships about twenty of these pre-written so you don't retype them, but nothing stops you from writing your own.\n\nHere's `Partial\u003CT>` in full — this is close to its real definition in `lib.es5.d.ts`:\n\n```ts\ntype MyPartial\u003CT> = {\n  [K in keyof T]?: T[K];\n};\n```\n\nRead it like a `for...in` loop over types: `K in keyof T` walks every key of `T`; `?:` adds the optional modifier to each one; `T[K]` keeps that property's original type. That's the entire mechanism. `Required\u003CT>` is the same loop with `-?` (remove the optional modifier) instead of `?`. `Readonly\u003CT>` is the same loop with `readonly` added. Three \"different\" utility types, one template, one character changed each time.\n\n`Pick` and `Omit` use the same mapped-type loop, but over a narrower or computed set of keys instead of all of `keyof T`:\n\n```ts\ntype MyPick\u003CT, K extends keyof T> = {\n  [P in K]: T[P];\n};\n\ntype MyOmit\u003CT, K extends keyof any> = MyPick\u003CT, Exclude\u003Ckeyof T, K>>;\n```\n\n`Omit` isn't its own primitive — it's `Pick` over \"every key except these,\" and \"every key except these\" is `Exclude`, a **conditional type**:\n\n```ts\ntype MyExclude\u003CT, U> = T extends U ? never : T;\n```\n\nRead that as: for each member of `T`, if it's assignable to `U`, replace it with `never` (which then vanishes from a union); otherwise keep it. This single four-word conditional is the engine behind `Exclude`, `Extract`, and — as you'll see in the edge cases section — the reason `Omit` behaves unexpectedly on union types.\n\n> **Key concept:** once you can read `[K in keyof T]` as \"loop over keys\" and `T extends U ? X : Y` as \"branch on assignability,\" every utility type in the standard library is legible on sight. You're not memorizing twenty names — you're applying two patterns.\n\n## Stage 1: the modifier types — Partial, Required, Readonly\n\nThese three change *which modifiers* apply to every property, without touching which properties exist.\n\n```ts\ninterface Config {\n  host: string;\n  port: number;\n  debug?: boolean;\n}\n\ntype PartialConfig = Partial\u003CConfig>;\n\u002F\u002F { host?: string; port?: number; debug?: boolean }\n\ntype RequiredConfig = Required\u003CConfig>;\n\u002F\u002F { host: string; port: number; debug: boolean }  — debug's \"?\" is gone\n\ntype ReadonlyConfig = Readonly\u003CConfig>;\n\u002F\u002F { readonly host: string; readonly port: number; readonly debug?: boolean }\n```\n\n`Partial` is the one you reach for constantly: update payloads, form state before every field is filled in, default-merging (`{ ...defaults, ...overrides }` where `overrides: Partial\u003CConfig>`). `Required` is its mirror — useful for asserting that, after validation, every optional field has in fact been filled:\n\n```ts\nfunction startServer(config: Required\u003CConfig>) {\n  \u002F\u002F debug is guaranteed defined here — the compiler enforces it at the call site\n}\n```\n\n`Readonly` prevents reassignment of top-level properties:\n\n```ts\nconst c: Readonly\u003CConfig> = { host: \"localhost\", port: 3000 };\nc.port = 4000; \u002F\u002F Error: Cannot assign to 'port' because it is a read-only property.\n```\n\n## Stage 2: the key-selection types — Pick, Omit, Record\n\nThese change *which properties exist*, keeping their original modifiers and types.\n\n```ts\ninterface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\ntype PublicUser = Pick\u003CUser, \"id\" | \"name\">;\n\u002F\u002F { id: string; name: string }\n\ntype UserWithoutId = Omit\u003CUser, \"id\">;\n\u002F\u002F { name: string; email: string; role: \"admin\" | \"member\" }\n```\n\n`Pick` says \"keep only these keys\"; `Omit` says \"keep everything except these keys.\" Use `Pick` when the kept set is small and stable (a public-facing subset); use `Omit` when you're removing one or two fields from an otherwise-large shape and don't want to re-list everything you're keeping.\n\n`Record\u003CK, T>` builds an object type from a set of keys and a single value type — useful for lookup tables and maps keyed by a known union:\n\n```ts\ntype Role = \"admin\" | \"member\" | \"guest\";\n\nconst roleLabels: Record\u003CRole, string> = {\n  admin: \"Administrator\",\n  member: \"Member\",\n  guest: \"Guest\",\n};\n\u002F\u002F omit one key, e.g. \"guest\", and TypeScript errors: property is missing\n```\n\nThat last line is `Record`'s real value over a plain index signature (`{ [key: string]: string }`): because the key type is a specific union, TypeScript checks that every member of the union has an entry, and rejects keys outside the union entirely.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-utility-types\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## Stage 3: the conditional types — Exclude, Extract, NonNullable\n\nThese operate on **unions**, not object shapes — think of them as set operations over the members of a union type.\n\n```ts\ntype Status = \"idle\" | \"loading\" | \"success\" | \"error\";\n\ntype NotIdle = Exclude\u003CStatus, \"idle\">;\n\u002F\u002F \"loading\" | \"success\" | \"error\"\n\ntype Settled = Extract\u003CStatus, \"success\" | \"error\">;\n\u002F\u002F \"success\" | \"error\"\n\ntype MaybeUser = User | null | undefined;\ntype DefiniteUser = NonNullable\u003CMaybeUser>;\n\u002F\u002F User\n```\n\n`Exclude\u003CT, U>` keeps the members of `T` that are **not** assignable to `U`; `Extract\u003CT, U>` keeps the members that **are**. They're complements of each other over the same two inputs. `NonNullable\u003CT>` strips `null` and `undefined` from `T` — it used to be defined as `Exclude\u003CT, null | undefined>`, but since TypeScript 4.8 it's `T & {}` instead (intersecting with the empty object type cancels `null` and `undefined` out, and unlike the old conditional type, the intersection form simplifies cleanly when `T` is itself generic).\n\nA real use: narrowing a discriminated union after a check that a plain `if` can't express as a type:\n\n```ts\nfunction isSettled(status: Status): status is Extract\u003CStatus, \"success\" | \"error\"> {\n  return status === \"success\" || status === \"error\";\n}\n```\n\n## Stage 4: the introspection types — ReturnType, Parameters, Awaited\n\nThese pull a type **out of a function signature or a Promise**, instead of transforming an object shape.\n\n```ts\nfunction createUser(name: string, role: \"admin\" | \"member\") {\n  return { id: crypto.randomUUID(), name, role };\n}\n\ntype NewUser = ReturnType\u003Ctypeof createUser>;\n\u002F\u002F { id: string; name: string; role: \"admin\" | \"member\" }\n\ntype CreateUserArgs = Parameters\u003Ctypeof createUser>;\n\u002F\u002F [name: string, role: \"admin\" | \"member\"]\n\nasync function fetchUser(): Promise\u003CUser> {\n  \u002F* ... *\u002F\n  return {} as User;\n}\n\ntype FetchedUser = Awaited\u003CReturnType\u003Ctypeof fetchUser>>;\n\u002F\u002F User — not Promise\u003CUser>\n```\n\nThese three are the way to keep a type in sync with a function's *implementation* instead of a parallel hand-written declaration. `typeof createUser` gets you the function's type; `ReturnType` and `Parameters` pull pieces back out of it. `Awaited\u003CT>` recursively unwraps nested promises (`Promise\u003CPromise\u003CUser>>` still resolves to `User`), which is what makes `Awaited\u003CReturnType\u003Ctypeof fetchUser>>` correct instead of leaving you with a dangling `Promise\u003CUser>`.\n\n## Edge cases and gotchas\n\n**Every built-in here is shallow.** `Partial\u003CT>`, `Required\u003CT>`, and `Readonly\u003CT>` only touch `T`'s own top-level properties:\n\n```ts\ninterface Profile {\n  user: { name: string; email: string };\n}\n\ntype PartialProfile = Partial\u003CProfile>;\n\u002F\u002F { user?: { name: string; email: string } }\n\u002F\u002F user.name and user.email are still required — Partial didn't recurse\nconst p: PartialProfile = { user: { name: \"Ada\" } }; \u002F\u002F Error: email is missing\n```\n\nIf you need every nested field optional too, you need a recursive mapped type (often called `DeepPartial`) — it isn't in the standard library because \"how deep\" and \"should arrays recurse too\" are decisions a one-size-fits-all utility can't make for you.\n\n**`Readonly` is compile-time only.** Nothing prevents `Object.freeze`-style mutation at runtime through an untyped reference, a cast, or library code that doesn't know about your type. `Readonly\u003CT>` stops *your* code from writing through *that* reference; it is not a runtime guarantee.\n\n**`Omit` on a union type silently drops fields it shouldn't.** This is the gotcha worth remembering. Recall `Omit\u003CT, K> = Pick\u003CT, Exclude\u003Ckeyof T, K>>`. The bug is in what `keyof` means for a union:\n\n```ts\ninterface Circle { kind: \"circle\"; radius: number }\ninterface Square { kind: \"square\"; side: number }\ntype Shape = Circle | Square;\n\ntype ShapeWithoutKind = Omit\u003CShape, \"kind\">;\n\u002F\u002F You'd expect: { radius: number } | { side: number }\n\u002F\u002F You actually get: {}\n```\n\n`keyof (Circle | Square)` is only the keys common to *every* member — here, just `\"kind\"` — because accessing a property on a union value only type-checks for properties every branch has. So `Exclude\u003Ckeyof Shape, \"kind\">` excludes the only common key and leaves `never`, and `Pick\u003CShape, never>` is `{}` for both branches. `radius` and `side` were never in the computation to begin with — they're silently gone, and `ShapeWithoutKind` is `{}`, not an error.\n\nThe fix is a **distributive** version that applies `Omit` to each union member separately before they're merged back into a union:\n\n```ts\ntype DistributiveOmit\u003CT, K extends PropertyKey> = T extends unknown\n  ? Omit\u003CT, K>\n  : never;\n\ntype ShapeWithoutKind = DistributiveOmit\u003CShape, \"kind\">;\n\u002F\u002F { radius: number } | { side: number } — correct\n```\n\nThe `T extends unknown ? ... : never` isn't a real check (every type extends `unknown`) — its only job is to make the conditional **distribute** over `T` when `T` is a union, running `Omit` once per branch instead of once on the merged type. This is the single most-cited TypeScript utility-type gotcha for a reason: it compiles cleanly and returns a plausible-looking empty object, so it tends to surface as a runtime bug, not a type error.\n\n## Best practices\n\n**Reach for a built-in utility type when** you're deriving a type from one that already exists and is the source of truth — an API response shape, a Prisma\u002Fdatabase model, a component's prop type. The derived type should update automatically when the source changes; that's the entire point.\n\n**Avoid them when** the \"derived\" type and the source type are only accidentally similar today and will diverge in meaning tomorrow. A `LoginFormValues` type that happens to share two field names with `User` isn't a `Pick\u003CUser, ...>` — it's its own type that should be declared as its own type.\n\n**Prefer `Pick` over `Omit`** when the kept set is small (2–3 fields) and stable — it reads as an explicit allowlist and doesn't silently include a field someone adds to the source type later without you noticing. **Prefer `Omit`** when you're removing one or two fields from an otherwise-large, evolving shape.\n\n**Reach for `DistributiveOmit` deliberately**, not by default — write `Omit` first, and only swap in the distributive version once you've confirmed the source type is (or might become) a union. Reaching for it reflexively everywhere adds a layer of indirection most object shapes never need.\n\n## FAQ\n\n### Does `Partial\u003CT>` make nested object properties optional too?\n\nNo. `Partial`, `Required`, and `Readonly` are shallow — they only transform `T`'s own top-level properties. A property whose type is itself an object keeps that object's original required\u002Foptional fields untouched. Use a hand-written recursive mapped type if you need every nested level.\n\n### Why does `Omit` return `{}` on a union type instead of erroring?\n\nBecause `Omit\u003CT, K>` is implemented as `Pick\u003CT, Exclude\u003Ckeyof T, K>>`, and `keyof` on a union type only yields the keys common to every member. If the only common key is the one you're omitting, the key set to keep becomes `never`, and `Pick\u003CT, never>` is `{}`. Use a distributive version (`T extends unknown ? Omit\u003CT, K> : never`) to get the per-branch result you expect. See \"Edge cases and gotchas\" above for the full example.\n\n### Can I combine utility types, like `Partial\u003CPick\u003CT, K>>`?\n\nYes — they're ordinary generic types, so they compose exactly like function calls. `Partial\u003CPick\u003CUser, \"name\" | \"email\">>` first narrows to two fields, then makes both optional. Order matters: `Pick\u003CPartial\u003CUser>, \"name\">` makes everything optional first, then keeps only `name` (still optional) — a different, usually less useful, result for this case.\n\n### What's the difference between `Record\u003Cstring, T>` and an index signature?\n\nFor a plain `string` key type they behave almost identically — `Record\u003Cstring, T>` is defined using an index signature internally. The difference matters when the key type is a specific union: `Record\u003CRole, string>` checks that every member of `Role` has an entry and rejects extra keys, while `{ [key: string]: string }` accepts any string key and enforces nothing about which keys must be present.\n\n### Does TypeScript have a built-in `DeepPartial` or `DeepReadonly`?\n\nNo. The standard library intentionally ships only shallow versions, because \"how deep,\" \"should this recurse into arrays and `Map`\u002F`Set`,\" and \"should functions be left alone\" are decisions that vary by use case. Write your own recursive mapped type, or use a small, well-tested library version if you need one across a codebase.\n\n## Cheat sheet\n\n| Task | Code | Notes |\n| --- | --- | --- |\n| Make every property optional | `Partial\u003CT>` | Shallow — nested objects keep their original required fields |\n| Make every property required | `Required\u003CT>` | Removes the `?` modifier everywhere, shallow |\n| Make every property readonly | `Readonly\u003CT>` | Compile-time only, shallow, no runtime freeze |\n| Keep only some properties | `Pick\u003CT, \"a\" \\| \"b\">` | Explicit allowlist; new fields on `T` are excluded by default |\n| Remove some properties | `Omit\u003CT, \"a\" \\| \"b\">` | Based on `Pick` + `Exclude` — see the union gotcha before using on a union |\n| Omit on a union, correctly | `T extends unknown ? Omit\u003CT, K> : never` | Forces per-branch distribution |\n| Build a lookup object type | `Record\u003CK, T>` | `K` a union enforces every key is present and no extra keys |\n| Keep union members assignable to `U` | `Extract\u003CT, U>` | |\n| Remove union members assignable to `U` | `Exclude\u003CT, U>` | Complement of `Extract` |\n| Strip `null`\u002F`undefined` from a type | `NonNullable\u003CT>` | `T & {}` since TS 4.8 (was `Exclude\u003CT, null \\| undefined>` before that) |\n| Get a function's return type | `ReturnType\u003Ctypeof fn>` | Use `typeof fn`, not `fn`, to reference the function's type |\n| Get a function's parameter tuple | `Parameters\u003Ctypeof fn>` | |\n| Unwrap a (possibly nested) Promise | `Awaited\u003CT>` | `Awaited\u003CReturnType\u003Ctypeof asyncFn>>` gives the resolved value's type |\n\n```ts\n\u002F\u002F the whole pattern, copy-paste ready\ninterface User {\n  id: string;\n  name: string;\n  email: string;\n  role: \"admin\" | \"member\";\n}\n\n\u002F\u002F derive, don't retype\ntype PublicUser = Pick\u003CUser, \"id\" | \"name\">;\ntype UpdateUserInput = Partial\u003COmit\u003CUser, \"id\">>;\ntype UserMap = Record\u003Cstring, User>;\n\ntype DistributiveOmit\u003CT, K extends PropertyKey> = T extends unknown\n  ? Omit\u003CT, K>\n  : never;\n```\n\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-utility-types\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n## Key takeaways\n\n- A utility type is a mapped type (`[K in keyof T]`) or a conditional type (`T extends U ? X : Y`) someone already wrote — not a special compiler feature. You can write your own.\n- `Partial`, `Required`, and `Readonly` change modifiers; `Pick`, `Omit`, and `Record` change which keys exist; `Exclude`\u002F`Extract`\u002F`NonNullable` operate on unions; `ReturnType`\u002F`Parameters`\u002F`Awaited` pull types out of function signatures.\n- Every built-in here is shallow — nested objects are untouched unless you write a recursive version yourself.\n- `Omit` on a union type can silently collapse to `{}`. If the source type might be a union, use a distributive `Omit`.\n\nThat `UpdateUserInput` from the opening — the one that quietly missed a field — was never going to catch up to `User` by being retyped more carefully. It needed to stop being its own type and become a computation over `User` instead. That's what every utility type in this guide is: not a list of twenty names to memorize, but two small tools — loop over keys, branch on assignability — applied again and again.\n\nWhich one bit you first: the shallow `Partial`, or the union `Omit`? Tell me in the comments — I'll compile the most common one into next week's \"gotchas\" post.\n\n\u003C!-- related:start -->\n\n## 📚 Read next\n\n- [TypeScript Generics: The Complete Guide (with Cheat Sheet)](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-generics)\n- [Web Workers in JavaScript: The Complete Guide](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-web-workers)\n- [JavaScript Proxy and Reflect: The Complete Guide](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-javascript-proxy-reflect)\n\n\u003C!-- related:end -->\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":47,"canonical":497,"description":49},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fweekly-typescript-utility-types","01a1df1b-1e04-73b8-9561-5c49b04a8e5f",{"name":500,"part":53,"total":501,"items":502},"Deep Dive",9,[503,508,512,516,520,525,529,533,534],{"slug":504,"title":505,"publishedAt":506,"readingMinutes":507},"weekly-javascript-event-loop","JavaScript Event Loop Explained: The Complete Guide","2026-07-13T09:36:33.464Z",13,{"slug":509,"title":510,"publishedAt":511,"readingMinutes":51},"weekly-typescript-generics","TypeScript Generics: The Complete Guide (with Cheat Sheet)","2026-07-20T09:23:23.621Z",{"slug":513,"title":514,"publishedAt":515,"readingMinutes":51},"weekly-cors-explained","CORS Explained: The Complete Guide (with Cheat Sheet)","2026-08-03T09:54:26.268Z",{"slug":517,"title":518,"publishedAt":519,"readingMinutes":51},"weekly-javascript-proxy-reflect","JavaScript Proxy and Reflect: The Complete Guide","2026-08-24T07:06:37.948Z",{"slug":521,"title":522,"publishedAt":523,"readingMinutes":524},"weekly-javascript-closures","JavaScript Closures: The Complete Guide (with Cheat Sheet)","2026-08-25T08:53:48.904Z",14,{"slug":526,"title":527,"publishedAt":528,"readingMinutes":524},"weekly-debounce-and-throttle","Debounce and Throttle in JavaScript: The Complete Guide","2026-08-31T13:12:14.139Z",{"slug":530,"title":531,"publishedAt":532,"readingMinutes":507},"weekly-web-workers","Web Workers in JavaScript: The Complete Guide","2026-09-07T12:03:05.323Z",{"slug":46,"title":47,"publishedAt":52,"readingMinutes":51},{"slug":535,"title":536,"publishedAt":537,"readingMinutes":51},"weekly-typescript-type-narrowing","TypeScript Type Narrowing: The Complete Guide","2026-11-27T11:46:59.418Z",{"id":539,"locked":18},"01a1df1b-1e30-7643-b6fc-c3a7097fc7e5",[541],{"id":542,"slug":46,"title":543,"_count":544},"01a1df1b-1e55-7189-9ee6-f61ce09e5895","TypeScript Utility Types",{"questions":53},[546],{"locale":13,"slug":46},{"id":542,"slug":46,"title":543,"_count":548,"questionCount":53},{"questions":53},[550,552,554,558,560,564,566,570,574,578,582,586],{"slug":73,"name":74,"articles":551},195,{"slug":67,"name":68,"articles":553},156,{"slug":555,"name":556,"articles":557},"frontend","Frontend",103,{"slug":70,"name":71,"articles":559},85,{"slug":561,"name":562,"articles":563},"css","Css",56,{"slug":61,"name":65,"articles":565},36,{"slug":567,"name":568,"articles":569},"performance","Performance",33,{"slug":571,"name":572,"articles":573},"programming","Programming",26,{"slug":575,"name":576,"articles":577},"react","React",23,{"slug":579,"name":580,"articles":581},"node","Node",19,{"slug":583,"name":584,"articles":585},"browser","Browser",18,{"slug":587,"name":588,"articles":507},"nextjs","Nextjs",[],{"items":591,"meta":717},[592,611,626,645,663,683,700],{"id":593,"slug":594,"title":595,"subtitle":48,"excerpt":596,"coverUrl":597,"locale":13,"readingMinutes":598,"publishedAt":599,"viewCount":600,"likeCount":19,"commentCount":19,"author":601,"vertical":602,"topic":603,"tags":604,"_count":609,"playground":610,"hasQuiz":17,"hasPlayground":17},"01a1fce0-dac8-71e2-bd25-94b1cc5aa337","typescript-template-literal-types","Template Literal Types Explained: Catching Path Typos at Compile Time","A typo'd dot-path like \"theme.colros.primary\" compiles clean and fails silently at runtime — template literal types make TypeScript catch it before you ship.","\u002Fmedia\u002Fcovers\u002Ftypescript-template-literal-types.png",6,"2026-11-27T11:49:01.332Z",27,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[605,606,607,608],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":594},{"id":612,"slug":535,"title":536,"subtitle":48,"excerpt":613,"coverUrl":614,"locale":13,"readingMinutes":51,"publishedAt":537,"viewCount":615,"likeCount":19,"commentCount":19,"author":616,"vertical":617,"topic":618,"tags":619,"_count":624,"playground":625,"hasQuiz":17,"hasPlayground":17},"01a1fce0-c9cc-7004-b075-6c0ff7c7b600","Learn how TypeScript type narrowing really works — typeof, instanceof, discriminated unions, and custom type guards — plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fweekly-typescript-type-narrowing.png",24,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[620,621,622,623],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":535},{"id":627,"slug":628,"title":629,"subtitle":48,"excerpt":630,"coverUrl":631,"locale":13,"readingMinutes":632,"publishedAt":633,"viewCount":634,"likeCount":19,"commentCount":19,"author":635,"vertical":636,"topic":637,"tags":638,"_count":643,"playground":644,"hasQuiz":17,"hasPlayground":17},"01a1fce0-bedd-7648-b22e-4b7afd1cce13","typescript-branded-types-nominal-typing","TypeScript Can't Tell userId From orderId. Branded Types Can.","TypeScript's structural typing treats userId and orderId as the same type if both are `string` — branded types make them incompatible at compile time.","\u002Fmedia\u002Fcovers\u002Ftypescript-branded-types-nominal-typing.png",5,"2026-11-27T11:45:58.086Z",12,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[639,640,641,642],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"slug":571,"name":572,"color":48},{"assessments":76},{"slug":628},{"id":646,"slug":647,"title":648,"subtitle":48,"excerpt":649,"coverUrl":650,"locale":13,"readingMinutes":632,"publishedAt":651,"viewCount":652,"likeCount":19,"commentCount":19,"author":653,"vertical":654,"topic":655,"tags":656,"_count":661,"playground":662,"hasQuiz":17,"hasPlayground":17},"01a1df1b-32db-7638-a86f-5cea99530919","typescript-noinfer-generic-widening","A Typo Widened My Generic Instead of Erroring. NoInfer\u003CT> Fixes It.","Why a typo'd default argument sailed through a generic function with zero errors — and how TypeScript's NoInfer\u003CT> stops it from silently widening the inferred type.","\u002Fmedia\u002Fcovers\u002Ftypescript-noinfer-generic-widening.png","2026-11-27T11:45:27.674Z",11,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[657,658,659,660],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":571,"name":572,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":647},{"id":664,"slug":665,"title":666,"subtitle":48,"excerpt":667,"coverUrl":668,"locale":13,"readingMinutes":669,"publishedAt":670,"viewCount":652,"likeCount":19,"commentCount":19,"author":671,"vertical":672,"topic":673,"tags":676,"_count":681,"playground":682,"hasQuiz":17,"hasPlayground":17},"01a1a1b0-49e9-711f-aea2-cbc2b73acc75","nestjs-weekly-interceptor-order","NestJS Interceptor Order: Why Stacking Breaks Your Cache","NestJS interceptor order decides whether a cache hit skips your response transform. Learn the onion model behind next.handle() — plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fnestjs-weekly-interceptor-order.png",16,"2026-11-27T11:44:57.150Z",{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":674,"name":675},"nestjs","Nestjs",[677,678,679,680],{"slug":674,"name":675,"color":48},{"slug":579,"name":580,"color":48},{"slug":61,"name":65,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":665},{"id":684,"slug":685,"title":686,"subtitle":48,"excerpt":687,"coverUrl":688,"locale":13,"readingMinutes":632,"publishedAt":689,"viewCount":31,"likeCount":19,"commentCount":19,"author":690,"vertical":691,"topic":692,"tags":693,"_count":698,"playground":699,"hasQuiz":17,"hasPlayground":17},"01a1df1b-2c58-7318-b1ea-6c6fcef9ff05","no-unchecked-indexed-access","arr[i] Isn't Always There. noUncheckedIndexedAccess Says So.","TypeScript types arr[i] as T, never T | undefined — even though the array might be empty. The noUncheckedIndexedAccess flag makes bracket indexing tell the truth.","\u002Fmedia\u002Fcovers\u002Fno-unchecked-indexed-access.png","2026-11-27T11:44:26.334Z",{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[694,695,696,697],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"slug":571,"name":572,"color":48},{"assessments":76},{"slug":685},{"id":701,"slug":702,"title":703,"subtitle":48,"excerpt":704,"coverUrl":705,"locale":13,"readingMinutes":632,"publishedAt":706,"viewCount":31,"likeCount":19,"commentCount":19,"author":707,"vertical":708,"topic":709,"tags":710,"_count":715,"playground":716,"hasQuiz":17,"hasPlayground":17},"01a1df1b-2879-726c-b86f-69cba3a4ecc3","typescript-exhaustiveness-checking-never","Your switch forgets a case. Exhaustiveness checking catches it.","How to make the TypeScript compiler fail the build when a switch statement doesn't handle every member of a union — using the `never` type.","\u002Fmedia\u002Fcovers\u002Ftypescript-exhaustiveness-checking-never.png","2026-11-27T11:43:55.790Z",{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[711,712,713,714],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":571,"name":572,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":702},{"page":76,"perPage":718,"total":565,"totalPages":598},7,"\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  id\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  email\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  role\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F hand-written, copy-pasted from User the week before this field existed\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UpdateUserInput\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  name\u003Cspan class=\"shj-oper\">?:\u003C\u002Fspan> string;\n  email\u003Cspan class=\"shj-oper\">?:\u003C\u002Fspan> string;\n  role\u003Cspan class=\"shj-oper\">?:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F id intentionally left off — you don't update the id\n\u003C\u002Fspan>  \u003Cspan class=\"shj-cmnt\">\u002F\u002F ...and whatever gets added to User next just won't show up here\n\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UpdateUserInput\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Partial\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"id\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { name?: string; email?: string; role?: (\"admin\" | \"member\") | undefined }\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MyPartial\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">in\u003C\u002Fspan> keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">?:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MyPick\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-num\">P\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">in\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-num\">P\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MyOmit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> keyof any\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MyPick\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Exclude\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;&gt;\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-oneline\" data-lang=\"ts\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MyExclude\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">U\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-num\">U\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> never \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>;\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Config\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  host\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  port\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan>;\n  debug\u003Cspan class=\"shj-oper\">?:\u003C\u002Fspan> boolean;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PartialConfig\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Partial\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Config\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { host?: string; port?: number; debug?: boolean }\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">RequiredConfig\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Required\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Config\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { host: string; port: number; debug: boolean }  — debug's \"?\" is gone\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ReadonlyConfig\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Readonly\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Config\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { readonly host: string; readonly port: number; readonly debug?: boolean }\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">startServer\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>config\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Required\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Config\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F debug is guaranteed defined here — the compiler enforces it at the call site\n\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> c\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Readonly\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Config\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> host\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"localhost\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> port\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">3000\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\nc\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>port \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-num\">4000\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F Error: Cannot assign to 'port' because it is a read-only property.\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  id\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  email\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  role\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PublicUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Pick\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"id\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"name\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { id: string; name: string }\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserWithoutId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"id\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { name: string; email: string; role: \"admin\" | \"member\" }\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Role\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"guest\"\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> roleLabels\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Record\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Role\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> string\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  admin\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"Administrator\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan>\n  member\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"Member\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan>\n  guest\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"Guest\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan>\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F omit one key, e.g. \"guest\", and TypeScript errors: property is missing\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Status\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"idle\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"loading\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"success\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"error\"\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">NotIdle\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Exclude\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Status\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"idle\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F \"loading\" | \"success\" | \"error\"\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Settled\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Extract\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Status\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"success\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"error\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F \"success\" | \"error\"\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">MaybeUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-num\">null\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-num\">undefined\u003C\u002Fspan>;\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">DefiniteUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">NonNullable\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">MaybeUser\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F User\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">isSettled\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>status\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Status\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> status is \u003Cspan class=\"shj-class\">Extract\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Status\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"success\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"error\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> status \u003Cspan class=\"shj-oper\">===\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"success\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">||\u003C\u002Fspan> status \u003Cspan class=\"shj-oper\">===\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"error\"\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">createUser\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> role\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> id\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> crypto\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">randomUUID\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> name\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> role \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">NewUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ReturnType\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">typeof\u003C\u002Fspan> createUser\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { id: string; name: string; role: \"admin\" | \"member\" }\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">CreateUserArgs\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Parameters\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">typeof\u003C\u002Fspan> createUser\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F [name: string, role: \"admin\" | \"member\"]\n\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">async\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">fetchUser\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Promise\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-cmnt\">\u002F* ... *\u002F\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">FetchedUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Awaited\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">ReturnType\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">typeof\u003C\u002Fspan> fetchUser\u003Cspan class=\"shj-oper\">&gt;&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F User — not Promise&lt;User&gt;\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Profile\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  user\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>; email\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PartialProfile\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Partial\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Profile\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { user?: { name: string; email: string } }\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F user.name and user.email are still required — Partial didn't recurse\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> p\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PartialProfile\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> user\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> name\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"Ada\"\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F Error: email is missing\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Circle\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> kind\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"circle\"\u003C\u002Fspan>; radius\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Square\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> kind\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"square\"\u003C\u002Fspan>; side\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Shape\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Circle\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Square\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ShapeWithoutKind\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Shape\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"kind\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F You'd expect: { radius: number } | { side: number }\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F You actually get: {}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">DistributiveOmit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PropertyKey\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> unknown\n  \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n  \u003Cspan class=\"shj-type\">: never\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">ShapeWithoutKind\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">DistributiveOmit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Shape\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"kind\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F { radius: number } | { side: number } — correct\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-multiline\" data-lang=\"ts\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-cmnt\">\u002F\u002F the whole pattern, copy-paste ready\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">interface\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  id\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  email\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n  role\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"admin\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"member\"\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F derive, don't retype\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PublicUser\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Pick\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"id\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"name\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UpdateUserInput\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Partial\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"id\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserMap\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Record\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>string\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-class\">User\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">DistributiveOmit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PropertyKey\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> unknown\n  \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Omit\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n  \u003Cspan class=\"shj-type\">: never\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":737},[]]