[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"article-typescript-template-literal-types":44,"search-suggestions":276,"path-membership-typescript-template-literal-types":317,"related-typescript-template-literal-types":318,"code:ts:true:17qci0b":444,"code:ts:true:613z2s":445,"code:ts:true:nn6l7n":446,"code:ts:true:1spz0fc":447,"code:ts:true:bmcr0l":448,"code:ts:true:1sa7ujq":449,"code:ts:true:d9mdop":450,"code:ts:true:agq9jd":451,"code:plain:true:zqbpt8":452,"comments-01a1fce0-dac8-71e2-bd25-94b1cc5aa337":453},[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":260,"seo":261,"translationGroupId":263,"series":48,"podcastUrl":48,"verticalId":5,"thread":264,"assessments":266,"translations":272,"quiz":274},"01a1fce0-dac8-71e2-bd25-94b1cc5aa337","typescript-template-literal-types","Template Literal Types Explained: Catching Path Typos at Compile Time",null,"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",25,{"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},"webdev","Webdev",{"slug":73,"name":74,"color":48},"tutorial","Tutorial",{"assessments":76},1,{"slug":46,"title":78},"Template literal types — type-safe path checker",{"blocks":80,"version":76},[81,85,91,94,97,100,105,108,111,115,118,121,124,127,131,134,138,141,144,148,151,155,158,162,165,169,172,175,179,182,187,190,193,196,199,202,205,208,211,214,217,220,223,226,229,232,235,238,241,244,247,250,253],{"id":82,"html":83,"type":84},"b1","\u003Cp>Somewhere in your codebase there&#39;s a function that looks like this:\u003C\u002Fp>","paragraph",{"id":86,"code":87,"type":88,"language":89,"highlight":90},"b2","function get(obj: any, path: string) {\n  return path.split(\".\").reduce((acc, key) => acc?.[key], obj);\n}\n\nconst primaryColor = get(config, \"theme.colros.primary\");","code","ts",[],{"id":92,"html":93,"type":84},"b3","\u003Cp>Read that path again. \u003Ccode>colros\u003C\u002Fcode>, not \u003Ccode>colors\u003C\u002Fcode>. TypeScript compiles it without a single complaint. The app ships. \u003Ccode>primaryColor\u003C\u002Fcode> is \u003Ccode>undefined\u003C\u002Fcode>, some fallback kicks in, and the button is the wrong shade of blue for three weeks before a designer notices and files a ticket nobody can reproduce on the first try.\u003C\u002Fp>",{"id":95,"html":96,"type":84},"b4","\u003Cp>The type system had everything it needed to catch this. \u003Ccode>config\u003C\u002Fcode> has a real, known shape. The bug is a four-character typo in a string literal sitting right there in the call site. And TypeScript let it through anyway — because as far as the compiler is concerned, \u003Ccode>path: string\u003C\u002Fcode> accepts literally any string.\u003C\u002Fp>",{"id":98,"html":99,"type":84},"b5","\u003Cp>Here&#39;s the part that&#39;s easy to miss: fixing this isn&#39;t a runtime check. It&#39;s a type you can write yourself, today, in about fifteen lines, using a feature TypeScript has shipped since 4.1.\u003C\u002Fp>",{"id":101,"html":102,"text":103,"type":104,"level":31},"b6","Why \u003Ccode>path: string\u003C\u002Fcode> can&#39;t save you","Why path: string can't save you","heading",{"id":106,"html":107,"type":84},"b7","\u003Cp>The naive \u003Ccode>get\u003C\u002Fcode> function above type-checks because \u003Ccode>string\u003C\u002Fcode> is the type. Every string is a \u003Ccode>string\u003C\u002Fcode>. TypeScript has no way to know that \u003Ccode>&quot;theme.colros.primary&quot;\u003C\u002Fcode> isn&#39;t a real path on \u003Ccode>config\u003C\u002Fcode> unless something narrower than \u003Ccode>string\u003C\u002Fcode> is doing the asking.\u003C\u002Fp>",{"id":109,"html":110,"type":84},"b8","\u003Cp>You could reach for \u003Ccode>keyof\u003C\u002Fcode> to type a single level:\u003C\u002Fp>",{"id":112,"code":113,"type":88,"language":89,"highlight":114},"b9","function getTop\u003CT, K extends keyof T>(obj: T, key: K): T[K] {\n  return obj[key];\n}",[],{"id":116,"html":117,"type":84},"b10","\u003Cp>That&#39;s genuinely safe — \u003Ccode>getTop(config, &quot;theem&quot;)\u003C\u002Fcode> is a compile error. But it only goes one property deep. The moment you want \u003Ccode>&quot;theme.colors.primary&quot;\u003C\u002Fcode>, you&#39;re back to a plain \u003Ccode>string\u003C\u002Fcode>, because \u003Ccode>keyof T\u003C\u002Fcode> gives you \u003Ccode>&quot;theme&quot;\u003C\u002Fcode>, not \u003Ccode>&quot;theme.colors.primary&quot;\u003C\u002Fcode>.\u003C\u002Fp>",{"id":119,"html":120,"type":84},"b11","\u003Cp>What you actually want is a type that looks at \u003Ccode>T\u003C\u002Fcode> and produces the union of \u003Cem>every valid dot-path through it\u003C\u002Fem> — and that&#39;s exactly what template literal types, combined with recursive conditional types, build.\u003C\u002Fp>",{"id":122,"html":123,"text":123,"type":104,"level":31},"b12","Building the path type",{"id":125,"html":126,"type":84},"b13","\u003Cp>Template literal types let you glue string literal types together the way you&#39;d glue strings with \u003Ccode>${}\u003C\u002Fcode> in a template string, except it happens at the type level:\u003C\u002Fp>",{"id":128,"code":129,"type":88,"language":89,"highlight":130},"b14","type Greeting = `Hello, ${string}`;\n\u002F\u002F matches \"Hello, world\", \"Hello, \", but not \"Hi there\"",[],{"id":132,"html":133,"type":84},"b15","\u003Cp>That&#39;s the primitive. The trick is combining it with a \u003Cstrong>mapped type over \u003Ccode>keyof T\u003C\u002Fcode>\u003C\u002Fstrong> that recurses into each property:\u003C\u002Fp>",{"id":135,"code":136,"type":88,"language":89,"highlight":137},"b16","type Primitive = string | number | boolean | bigint | symbol | undefined | null | Date;\n\ntype Paths\u003CT> = T extends Primitive\n  ? never\n  : T extends readonly unknown[]\n    ? never\n    : {\n        [K in keyof T & string]: T[K] extends Primitive\n          ? K\n          : K | `${K}.${Paths\u003CT[K]>}`;\n      }[keyof T & string];",[],{"id":139,"html":140,"type":84},"b17","\u003Cp>Read it as: for every key \u003Ccode>K\u003C\u002Fcode> on \u003Ccode>T\u003C\u002Fcode>, if the value at that key is a primitive, the path stops there — just \u003Ccode>K\u003C\u002Fcode>. If it&#39;s an object, the path is either \u003Ccode>K\u003C\u002Fcode> itself or \u003Ccode>K\u003C\u002Fcode> followed by a dot and a valid path \u003Cem>through that nested object\u003C\u002Fem>. The \u003Ccode>[keyof T &amp; string]\u003C\u002Fcode> at the end collapses the mapped type into a plain union.\u003C\u002Fp>",{"id":142,"html":143,"type":84},"b18","\u003Cp>Give it this \u003Ccode>Config\u003C\u002Fcode>:\u003C\u002Fp>",{"id":145,"code":146,"type":88,"language":89,"highlight":147},"b19","interface Config {\n  theme: {\n    colors: { primary: string; secondary: string };\n    darkMode: boolean;\n  };\n  name: string;\n}",[],{"id":149,"html":150,"type":84},"b20","\u003Cp>\u003Ccode>Paths&lt;Config&gt;\u003C\u002Fcode> resolves to:\u003C\u002Fp>",{"id":152,"code":153,"type":88,"language":89,"highlight":154},"b21","\"name\" | \"theme\" | \"theme.colors\" | \"theme.darkMode\" | \"theme.colors.primary\" | \"theme.colors.secondary\"",[],{"id":156,"html":157,"type":84},"b22","\u003Cp>Every single one of those strings is a real path on a real \u003Ccode>Config\u003C\u002Fcode>. There&#39;s no way to spell a typo and have it type-check, because the union was generated \u003Cem>from the object&#39;s own declared shape\u003C\u002Fem>, not typed by hand.\u003C\u002Fp>",{"id":159,"html":160,"text":161,"type":104,"level":31},"b23","Making \u003Ccode>get\u003C\u002Fcode> use it","Making get use it",{"id":163,"html":164,"type":84},"b24","\u003Cp>The path type alone doesn&#39;t fix \u003Ccode>get\u003C\u002Fcode> — you still need the return type to follow the path, or every call collapses to \u003Ccode>unknown\u003C\u002Fcode>. That&#39;s a second recursive conditional type, walking the string apart instead of the object:\u003C\u002Fp>",{"id":166,"code":167,"type":88,"language":89,"highlight":168},"b25","type PathValue\u003CT, P extends string> = P extends `${infer Head}.${infer Rest}`\n  ? Head extends keyof T\n    ? PathValue\u003CT[Head], Rest>\n    : never\n  : P extends keyof T\n    ? T[P]\n    : never;\n\nfunction get\u003CT, P extends Paths\u003CT>>(obj: T, path: P): PathValue\u003CT, P> {\n  const parts = (path as string).split(\".\");\n  let current: unknown = obj;\n  for (const part of parts) current = (current as Record\u003Cstring, unknown>)?.[part];\n  return current as PathValue\u003CT, P>;\n}",[],{"id":170,"html":171,"type":84},"b26","\u003Cp>\u003Ccode>PathValue\u003C\u002Fcode> pattern-matches the string literal \u003Ccode>P\u003C\u002Fcode> against \u003Ccode>`${infer Head}.${infer Rest}`\u003C\u002Fcode>. If there&#39;s a dot, it peels off the first segment and recurses on the rest; once there&#39;s no dot left, it looks the final segment up with \u003Ccode>T[P]\u003C\u002Fcode> directly.\u003C\u002Fp>",{"id":173,"html":174,"type":84},"b27","\u003Cp>Now run the typo through it:\u003C\u002Fp>",{"id":176,"code":177,"type":88,"language":89,"highlight":178},"b28","get(config, \"theme.colors.primary\"); \u002F\u002F string — correct, and TypeScript knows it\nget(config, \"theme.colros.primary\"); \u002F\u002F compile error, not a runtime surprise",[],{"id":180,"html":181,"type":84},"b29","\u003Cp>That second line doesn&#39;t run. It doesn&#39;t ship. \u003Ccode>tsc\u003C\u002Fcode> stops it with:\u003C\u002Fp>",{"id":183,"code":184,"type":88,"language":185,"highlight":186},"b30","Argument of type '\"theme.colros.primary\"' is not assignable to parameter of type\n'\"name\" | \"theme.colors.primary\" | \"theme\" | \"theme.colors\" | \"theme.darkMode\" | \"theme.colors.secondary\"'.","plain",[],{"id":188,"html":189,"type":84},"b31","\u003Cp>I ran both versions through \u003Ccode>tsc --strict\u003C\u002Fcode> before writing this — the naive one takes the typo silently, the typed one refuses to compile it. That&#39;s the entire payoff: the same information that used to surface as a confused designer three weeks later now surfaces as a red squiggle while you&#39;re still typing the call.\u003C\u002Fp>",{"id":191,"html":192,"type":84},"b32","\u003Cp>If you&#39;ve ever typed a field name into react-hook-form&#39;s \u003Ccode>register(&quot;user.address.city&quot;)\u003C\u002Fcode> and had autocomplete walk you through it, you&#39;ve already used a type built this same way — their \u003Ccode>Path&lt;T&gt;\u003C\u002Fcode> helper exists to solve exactly this problem for form fields.\u003C\u002Fp>",{"id":194,"html":195,"text":195,"type":104,"level":31},"b33","Where this gets expensive",{"id":197,"html":198,"type":84},"b34","\u003Cp>Two honest limits, because a type that silently falls back to \u003Ccode>any\u003C\u002Fcode> on hard cases is worse than no type at all.\u003C\u002Fp>",{"id":200,"html":201,"type":84},"b35","\u003Cp>\u003Cstrong>Depth.\u003C\u002Fstrong> TypeScript caps how deeply it will recurse into a conditional type. For most app config, form, or API-response shapes — three or four levels of nesting — \u003Ccode>Paths&lt;T&gt;\u003C\u002Fcode> resolves fast and correctly. Push it at a genuinely deep, non-recursive chain (I tested around sixty levels) and you&#39;ll hit \u003Ccode>Type instantiation is excessively deep and possibly infinite\u003C\u002Fcode>. At that point the fix is a depth-limited variant (cap the recursion with a counter type), not pushing harder on the same approach.\u003C\u002Fp>",{"id":203,"html":204,"type":84},"b36","\u003Cp>A type that references \u003Cem>itself\u003C\u002Fem> behaves differently, and worse. Give \u003Ccode>Paths\u003C\u002Fcode> an \u003Ccode>interface TreeNode { value: string; children: TreeNode }\u003C\u002Fcode> and TypeScript refuses outright with a different error — \u003Ccode>Type of property &#39;children&#39; circularly references itself in mapped type\u003C\u002Fcode> — because the mapped type can&#39;t even start resolving a property whose type is itself. But the shape real trees actually use, \u003Ccode>children: TreeNode[]\u003C\u002Fcode>, doesn&#39;t error at all: \u003Ccode>Paths&lt;T&gt;\u003C\u002Fcode> already bails out on arrays, so \u003Ccode>Paths&lt;TreeNode&gt;\u003C\u002Fcode> quietly resolves to just \u003Ccode>&quot;value&quot; | &quot;children&quot;\u003C\u002Fcode> — technically correct, but silently blind to everything nested under \u003Ccode>children\u003C\u002Fcode>. That&#39;s the failure mode worth losing sleep over: not a loud compiler error, but a type that compiles clean and just stops short of where you assumed it reached.\u003C\u002Fp>",{"id":206,"html":207,"type":84},"b37","\u003Cp>\u003Cstrong>Arrays.\u003C\u002Fstrong> The \u003Ccode>Paths&lt;T&gt;\u003C\u002Fcode> above explicitly bails on arrays (\u003Ccode>T extends readonly unknown[] ? never\u003C\u002Fcode>) rather than pretending to support them. Indexing into arrays by position (\u003Ccode>items.0.name\u003C\u002Fcode>) is a real, solvable extension — using \u003Ccode>`${number}`\u003C\u002Fcode> as a key — but it&#39;s a deliberately separate problem from object paths, and bolting it on half-finished is how you end up with a type that compiles but lies.\u003C\u002Fp>",{"id":209,"html":210,"type":84},"b38","\u003Cp>Neither of these is a reason to skip the type. They&#39;re the reason to know, before you reach for it on a 12-level GraphQL response, that you&#39;re past where it comfortably lives.\u003C\u002Fp>",{"id":212,"html":213,"type":84},"b39","\u003C!-- playground:start -->",{"id":215,"html":216,"text":216,"type":104,"level":31},"b40","🎮 Try it yourself",{"id":218,"html":219,"type":84},"b41","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-template-literal-types\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":221,"html":222,"type":84},"b42","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":224,"html":225,"type":84},"b43","\u003C!-- playground:end -->",{"id":227,"html":228,"type":84},"b44","\u003Cp>The next time you write \u003Ccode>obj[a][b][c]\u003C\u002Fcode> with a string you typed from memory, ask yourself whether TypeScript actually checked it — or just trusted you. What&#39;s the last path typo that made it past your compiler and into production? I&#39;d genuinely like to know I&#39;m not the only one.\u003C\u002Fp>",{"id":230,"html":231,"type":84},"b45","\u003C!-- quiz:start -->",{"id":233,"html":234,"text":234,"type":104,"level":31},"b46","🧠 Test yourself",{"id":236,"html":237,"type":84},"b47","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-template-literal-types\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":239,"html":240,"type":84},"b48","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":242,"html":243,"type":84},"b49","\u003C!-- quiz:end -->",{"id":245,"type":246},"b50","divider",{"id":248,"html":249,"type":84},"b51","\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":251,"html":252,"type":84},"b52","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":254,"type":255,"items":256,"ordered":18},"b53","list",[257,258,259],"⭐ \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>","Somewhere in your codebase there's a function that looks like this:\n\n```ts\nfunction get(obj: any, path: string) {\n  return path.split(\".\").reduce((acc, key) => acc?.[key], obj);\n}\n\nconst primaryColor = get(config, \"theme.colros.primary\");\n```\n\nRead that path again. `colros`, not `colors`. TypeScript compiles it without a single complaint. The app ships. `primaryColor` is `undefined`, some fallback kicks in, and the button is the wrong shade of blue for three weeks before a designer notices and files a ticket nobody can reproduce on the first try.\n\nThe type system had everything it needed to catch this. `config` has a real, known shape. The bug is a four-character typo in a string literal sitting right there in the call site. And TypeScript let it through anyway — because as far as the compiler is concerned, `path: string` accepts literally any string.\n\nHere's the part that's easy to miss: fixing this isn't a runtime check. It's a type you can write yourself, today, in about fifteen lines, using a feature TypeScript has shipped since 4.1.\n\n## Why `path: string` can't save you\n\nThe naive `get` function above type-checks because `string` is the type. Every string is a `string`. TypeScript has no way to know that `\"theme.colros.primary\"` isn't a real path on `config` unless something narrower than `string` is doing the asking.\n\nYou could reach for `keyof` to type a single level:\n\n```ts\nfunction getTop\u003CT, K extends keyof T>(obj: T, key: K): T[K] {\n  return obj[key];\n}\n```\n\nThat's genuinely safe — `getTop(config, \"theem\")` is a compile error. But it only goes one property deep. The moment you want `\"theme.colors.primary\"`, you're back to a plain `string`, because `keyof T` gives you `\"theme\"`, not `\"theme.colors.primary\"`.\n\nWhat you actually want is a type that looks at `T` and produces the union of *every valid dot-path through it* — and that's exactly what template literal types, combined with recursive conditional types, build.\n\n## Building the path type\n\nTemplate literal types let you glue string literal types together the way you'd glue strings with `${}` in a template string, except it happens at the type level:\n\n```ts\ntype Greeting = `Hello, ${string}`;\n\u002F\u002F matches \"Hello, world\", \"Hello, \", but not \"Hi there\"\n```\n\nThat's the primitive. The trick is combining it with a **mapped type over `keyof T`** that recurses into each property:\n\n```ts\ntype Primitive = string | number | boolean | bigint | symbol | undefined | null | Date;\n\ntype Paths\u003CT> = T extends Primitive\n  ? never\n  : T extends readonly unknown[]\n    ? never\n    : {\n        [K in keyof T & string]: T[K] extends Primitive\n          ? K\n          : K | `${K}.${Paths\u003CT[K]>}`;\n      }[keyof T & string];\n```\n\nRead it as: for every key `K` on `T`, if the value at that key is a primitive, the path stops there — just `K`. If it's an object, the path is either `K` itself or `K` followed by a dot and a valid path *through that nested object*. The `[keyof T & string]` at the end collapses the mapped type into a plain union.\n\nGive it this `Config`:\n\n```ts\ninterface Config {\n  theme: {\n    colors: { primary: string; secondary: string };\n    darkMode: boolean;\n  };\n  name: string;\n}\n```\n\n`Paths\u003CConfig>` resolves to:\n\n```ts\n\"name\" | \"theme\" | \"theme.colors\" | \"theme.darkMode\" | \"theme.colors.primary\" | \"theme.colors.secondary\"\n```\n\nEvery single one of those strings is a real path on a real `Config`. There's no way to spell a typo and have it type-check, because the union was generated *from the object's own declared shape*, not typed by hand.\n\n## Making `get` use it\n\nThe path type alone doesn't fix `get` — you still need the return type to follow the path, or every call collapses to `unknown`. That's a second recursive conditional type, walking the string apart instead of the object:\n\n```ts\ntype PathValue\u003CT, P extends string> = P extends `${infer Head}.${infer Rest}`\n  ? Head extends keyof T\n    ? PathValue\u003CT[Head], Rest>\n    : never\n  : P extends keyof T\n    ? T[P]\n    : never;\n\nfunction get\u003CT, P extends Paths\u003CT>>(obj: T, path: P): PathValue\u003CT, P> {\n  const parts = (path as string).split(\".\");\n  let current: unknown = obj;\n  for (const part of parts) current = (current as Record\u003Cstring, unknown>)?.[part];\n  return current as PathValue\u003CT, P>;\n}\n```\n\n`PathValue` pattern-matches the string literal `P` against `` `${infer Head}.${infer Rest}` ``. If there's a dot, it peels off the first segment and recurses on the rest; once there's no dot left, it looks the final segment up with `T[P]` directly.\n\nNow run the typo through it:\n\n```ts\nget(config, \"theme.colors.primary\"); \u002F\u002F string — correct, and TypeScript knows it\nget(config, \"theme.colros.primary\"); \u002F\u002F compile error, not a runtime surprise\n```\n\nThat second line doesn't run. It doesn't ship. `tsc` stops it with:\n\n```\nArgument of type '\"theme.colros.primary\"' is not assignable to parameter of type\n'\"name\" | \"theme.colors.primary\" | \"theme\" | \"theme.colors\" | \"theme.darkMode\" | \"theme.colors.secondary\"'.\n```\n\nI ran both versions through `tsc --strict` before writing this — the naive one takes the typo silently, the typed one refuses to compile it. That's the entire payoff: the same information that used to surface as a confused designer three weeks later now surfaces as a red squiggle while you're still typing the call.\n\nIf you've ever typed a field name into react-hook-form's `register(\"user.address.city\")` and had autocomplete walk you through it, you've already used a type built this same way — their `Path\u003CT>` helper exists to solve exactly this problem for form fields.\n\n## Where this gets expensive\n\nTwo honest limits, because a type that silently falls back to `any` on hard cases is worse than no type at all.\n\n**Depth.** TypeScript caps how deeply it will recurse into a conditional type. For most app config, form, or API-response shapes — three or four levels of nesting — `Paths\u003CT>` resolves fast and correctly. Push it at a genuinely deep, non-recursive chain (I tested around sixty levels) and you'll hit `Type instantiation is excessively deep and possibly infinite`. At that point the fix is a depth-limited variant (cap the recursion with a counter type), not pushing harder on the same approach.\n\nA type that references *itself* behaves differently, and worse. Give `Paths` an `interface TreeNode { value: string; children: TreeNode }` and TypeScript refuses outright with a different error — `Type of property 'children' circularly references itself in mapped type` — because the mapped type can't even start resolving a property whose type is itself. But the shape real trees actually use, `children: TreeNode[]`, doesn't error at all: `Paths\u003CT>` already bails out on arrays, so `Paths\u003CTreeNode>` quietly resolves to just `\"value\" | \"children\"` — technically correct, but silently blind to everything nested under `children`. That's the failure mode worth losing sleep over: not a loud compiler error, but a type that compiles clean and just stops short of where you assumed it reached.\n\n**Arrays.** The `Paths\u003CT>` above explicitly bails on arrays (`T extends readonly unknown[] ? never`) rather than pretending to support them. Indexing into arrays by position (`items.0.name`) is a real, solvable extension — using `` `${number}` `` as a key — but it's a deliberately separate problem from object paths, and bolting it on half-finished is how you end up with a type that compiles but lies.\n\nNeither of these is a reason to skip the type. They're the reason to know, before you reach for it on a 12-level GraphQL response, that you're past where it comfortably lives.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-template-literal-types\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\nThe next time you write `obj[a][b][c]` with a string you typed from memory, ask yourself whether TypeScript actually checked it — or just trusted you. What's the last path typo that made it past your compiler and into production? I'd genuinely like to know I'm not the only one.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-template-literal-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\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":262,"description":49},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-template-literal-types","01a1fce0-dac8-71e2-bd25-9a77d1847493",{"id":265,"locked":18},"01a1fce0-dafd-7412-8e93-e0fb87edd013",[267],{"id":268,"slug":46,"title":269,"_count":270},"01a1fce0-db1d-7319-b048-2c28003dafe4","Template literal types — type-safe object paths",{"questions":271},8,[273],{"locale":13,"slug":46},{"id":268,"slug":46,"title":269,"_count":275,"questionCount":271},{"questions":271},[277,279,281,285,287,291,293,297,301,305,309,313],{"slug":70,"name":71,"articles":278},195,{"slug":67,"name":68,"articles":280},156,{"slug":282,"name":283,"articles":284},"frontend","Frontend",103,{"slug":73,"name":74,"articles":286},85,{"slug":288,"name":289,"articles":290},"css","Css",56,{"slug":61,"name":65,"articles":292},36,{"slug":294,"name":295,"articles":296},"performance","Performance",33,{"slug":298,"name":299,"articles":300},"programming","Programming",26,{"slug":302,"name":303,"articles":304},"react","React",23,{"slug":306,"name":307,"articles":308},"node","Node",19,{"slug":310,"name":311,"articles":312},"browser","Browser",18,{"slug":314,"name":315,"articles":316},"nextjs","Nextjs",13,[],{"items":319,"meta":442},[320,331,350,369,387,408,425],{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":300,"likeCount":19,"commentCount":19,"author":321,"vertical":322,"topic":323,"tags":324,"_count":329,"playground":330,"hasQuiz":17,"hasPlayground":17},{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[325,326,327,328],{"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":46},{"id":332,"slug":333,"title":334,"subtitle":48,"excerpt":335,"coverUrl":336,"locale":13,"readingMinutes":337,"publishedAt":338,"viewCount":339,"likeCount":19,"commentCount":19,"author":340,"vertical":341,"topic":342,"tags":343,"_count":348,"playground":349,"hasQuiz":17,"hasPlayground":17},"01a1fce0-c9cc-7004-b075-6c0ff7c7b600","weekly-typescript-type-narrowing","TypeScript Type Narrowing: The Complete Guide","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",15,"2026-11-27T11:46:59.418Z",24,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[344,345,346,347],{"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":333},{"id":351,"slug":352,"title":353,"subtitle":48,"excerpt":354,"coverUrl":355,"locale":13,"readingMinutes":356,"publishedAt":357,"viewCount":358,"likeCount":19,"commentCount":19,"author":359,"vertical":360,"topic":361,"tags":362,"_count":367,"playground":368,"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",11,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[363,364,365,366],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":298,"name":299,"color":48},{"assessments":76},{"slug":352},{"id":370,"slug":371,"title":372,"subtitle":48,"excerpt":373,"coverUrl":374,"locale":13,"readingMinutes":356,"publishedAt":375,"viewCount":376,"likeCount":19,"commentCount":19,"author":377,"vertical":378,"topic":379,"tags":380,"_count":385,"playground":386,"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",9,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[381,382,383,384],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":298,"name":299,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":371},{"id":388,"slug":389,"title":390,"subtitle":48,"excerpt":391,"coverUrl":392,"locale":13,"readingMinutes":393,"publishedAt":394,"viewCount":395,"likeCount":19,"commentCount":19,"author":396,"vertical":397,"topic":398,"tags":401,"_count":406,"playground":407,"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",10,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":399,"name":400},"nestjs","Nestjs",[402,403,404,405],{"slug":399,"name":400,"color":48},{"slug":306,"name":307,"color":48},{"slug":61,"name":65,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":389},{"id":409,"slug":410,"title":411,"subtitle":48,"excerpt":412,"coverUrl":413,"locale":13,"readingMinutes":356,"publishedAt":414,"viewCount":31,"likeCount":19,"commentCount":19,"author":415,"vertical":416,"topic":417,"tags":418,"_count":423,"playground":424,"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},[419,420,421,422],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":298,"name":299,"color":48},{"assessments":76},{"slug":410},{"id":426,"slug":427,"title":428,"subtitle":48,"excerpt":429,"coverUrl":430,"locale":13,"readingMinutes":356,"publishedAt":431,"viewCount":31,"likeCount":19,"commentCount":19,"author":432,"vertical":433,"topic":434,"tags":435,"_count":440,"playground":441,"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},[436,437,438,439],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":298,"name":299,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":427},{"page":76,"perPage":443,"total":292,"totalPages":51},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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">get\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>obj\u003Cspan class=\"shj-type\">: any\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> path\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> path\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">split\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\".\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">reduce\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>acc\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> key\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> acc\u003Cspan class=\"shj-oper\">?.\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>key\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> obj\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> primaryColor \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">get\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>config\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colros.primary\"\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>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> getTop\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-bracket\">(\u003C\u002Fspan>obj\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> key\u003Cspan class=\"shj-oper\">:\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\">K\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> obj\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>key\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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Greeting\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-str\">`Hello, \u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>string\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">`\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F matches \"Hello, world\", \"Hello, \", but not \"Hi there\"\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\">Primitive\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> string \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> number \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> boolean \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> bigint \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> symbol \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-num\">undefined\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-num\">null\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Date\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Paths\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-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Primitive\u003C\u002Fspan>\n  \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> never\n  \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">readonly\u003C\u002Fspan> unknown\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\n    \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> never\n    \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-oper\">&#38;\u003C\u002Fspan> string\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> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Primitive\u003C\u002Fspan>\n          \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\n          \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">K\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">`\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>\u003Cspan class=\"shj-num\">K\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">.\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Paths\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\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>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">`\u003C\u002Fspan>;\n      \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">&#38;\u003C\u002Fspan> string\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>\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  theme\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    colors\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> primary\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>; secondary\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n    darkMode\u003Cspan class=\"shj-type\">: boolean\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n  name\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-ts shj-oneline\" data-lang=\"ts\">\u003Cspan class=\"shj-str\">\"name\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colors\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.darkMode\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colors.primary\"\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">|\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colors.secondary\"\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\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PathValue\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\">P\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> string\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-num\">P\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-str\">`\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>infer \u003Cspan class=\"shj-class\">Head\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">.\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>infer \u003Cspan class=\"shj-class\">Rest\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">`\u003C\u002Fspan>\n  \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Head\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\n    \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PathValue\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>\u003Cspan class=\"shj-class\">Head\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Rest\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n    \u003Cspan class=\"shj-type\">: never\u003C\u002Fspan>\n  \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">P\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> keyof \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\n    \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-type\">: never\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">get\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\">P\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">extends\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Paths\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>obj\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">T\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> path\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">P\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PathValue\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\">P\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> parts \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>path \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> string\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">split\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\".\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">let\u003C\u002Fspan> current\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> unknown \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> obj;\n  \u003Cspan class=\"shj-kwd\">for\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> part \u003Cspan class=\"shj-kwd\">of\u003C\u002Fspan> parts\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> current \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>current \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Record\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>string\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> unknown\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">?.\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>part\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> current \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">PathValue\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\">P\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">get\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>config\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colors.primary\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F string — correct, and TypeScript knows it\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">get\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>config\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"theme.colros.primary\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F compile error, not a runtime surprise\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-plain shj-multiline\" data-lang=\"plain\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">Argument of type '\u003Cspan class=\"shj-str\">\"theme.colros.primary\"\u003C\u002Fspan>' is not assignable to parameter of type\n'\u003Cspan class=\"shj-str\">\"name\"\u003C\u002Fspan> | \u003Cspan class=\"shj-str\">\"theme.colors.primary\"\u003C\u002Fspan> | \u003Cspan class=\"shj-str\">\"theme\"\u003C\u002Fspan> | \u003Cspan class=\"shj-str\">\"theme.colors\"\u003C\u002Fspan> | \u003Cspan class=\"shj-str\">\"theme.darkMode\"\u003C\u002Fspan> | \u003Cspan class=\"shj-str\">\"theme.colors.secondary\"\u003C\u002Fspan>'.\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":454},[]]