[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"article-typescript-branded-types-nominal-typing":44,"path-membership-typescript-branded-types-nominal-typing":257,"search-suggestions":258,"related-typescript-branded-types-nominal-typing":299,"code:ts:true:1m2gkgz":424,"code:ts:true:ofv1z8":425,"code:ts:true:16kbcg4":426,"code:ts:true:1o3145e":427,"code:ts:true:stv1yz":428,"comments-01a1fce0-bedd-7648-b22e-4b7afd1cce13":429},[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":241,"seo":242,"translationGroupId":244,"series":48,"podcastUrl":48,"verticalId":5,"thread":245,"assessments":247,"translations":253,"quiz":255},"01a1fce0-bedd-7648-b22e-4b7afd1cce13","typescript-branded-types-nominal-typing","TypeScript Can't Tell userId From orderId. Branded Types Can.",null,"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",10,{"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},"programming","Programming",{"assessments":76},1,{"slug":46,"title":78},"Branded types — interactive playground",{"blocks":80,"version":76},[81,85,88,91,95,98,104,107,110,113,117,120,124,127,131,134,138,141,145,148,151,155,158,161,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207,210,213,216,223,226,229,232,235],{"id":82,"html":83,"type":84},"b1","\u003Cp>A support engineer is looking at a refund ticket. They copy an ID from one browser tab, paste it into another, and call \u003Ccode>issueRefund(id)\u003C\u002Fcode>. The function signature says \u003Ccode>id: string\u003C\u002Fcode>. The ID they pasted is a \u003Ccode>string\u003C\u002Fcode>. TypeScript has nothing to say about it.\u003C\u002Fp>","paragraph",{"id":86,"html":87,"type":84},"b2","\u003Cp>The refund goes out. Just not to the customer who filed the ticket — to whoever that ID actually belonged to.\u003C\u002Fp>",{"id":89,"html":90,"type":84},"b3","\u003Cp>Nobody wrote a bug here. The types were never wrong. That&#39;s the part that should bother you.\u003C\u002Fp>",{"id":92,"html":93,"text":93,"type":94,"level":31},"b4","Two IDs, one type, zero complaints","heading",{"id":96,"html":97,"type":84},"b5","\u003Cp>Here&#39;s the function, trimmed to the part that matters:\u003C\u002Fp>",{"id":99,"code":100,"type":101,"language":102,"highlight":103},"b6","function issueRefund(userId: string, amountCents: number) {\n  \u002F\u002F looks up the user, credits their account\n}\n\nfunction getOrder(orderId: string) {\n  \u002F\u002F fetches the order\n}\n\nconst order = getOrder(\"ord_9f21\");\nissueRefund(order.customerOrderId, 500); \u002F\u002F ord_9f21, not a user id","code","ts",[],{"id":105,"html":106,"type":84},"b7","\u003Cp>That last line compiles clean. \u003Ccode>order.customerOrderId\u003C\u002Fcode> is a \u003Ccode>string\u003C\u002Fcode>. \u003Ccode>issueRefund\u003C\u002Fcode> wants a \u003Ccode>string\u003C\u002Fcode>. TypeScript checks shapes, not names — to the compiler, \u003Ccode>UserId\u003C\u002Fcode> and \u003Ccode>OrderId\u003C\u002Fcode> were never distinct in the first place, because nobody declared them. They&#39;re both just \u003Ccode>string\u003C\u002Fcode>, and every \u003Ccode>string\u003C\u002Fcode> is interchangeable with every other \u003Ccode>string\u003C\u002Fcode>.\u003C\u002Fp>",{"id":108,"html":109,"type":84},"b8","\u003Cp>This is structural typing, and 95% of the time it&#39;s exactly what you want — it&#39;s why you can pass a plain object literal anywhere an interface is expected without extending anything. The 5% is IDs, currency amounts, sanitized vs. raw HTML, and anything else where the \u003Cem>shape\u003C\u002Fem> is identical but the \u003Cem>meaning\u003C\u002Fem> isn&#39;t allowed to mix.\u003C\u002Fp>",{"id":111,"html":112,"type":84},"b9","\u003Cp>Spot where you&#39;d make this mistake yourself? Rename the variables and it&#39;s not obvious at all — which is exactly why it ships.\u003C\u002Fp>",{"id":114,"html":115,"text":116,"type":94,"level":31},"b10","Why \u003Ccode>type UserId = string\u003C\u002Fcode> doesn&#39;t help","Why type UserId = string doesn't help",{"id":118,"html":119,"type":84},"b11","\u003Cp>The first instinct is a type alias:\u003C\u002Fp>",{"id":121,"code":122,"type":101,"language":102,"highlight":123},"b12","type UserId = string;\ntype OrderId = string;\n\nfunction issueRefund(userId: UserId, amountCents: number) { \u002F* ... *\u002F }\n\nconst orderId: OrderId = \"ord_9f21\";\nissueRefund(orderId, 500); \u002F\u002F still compiles",[],{"id":125,"html":126,"type":84},"b13","\u003Cp>Still compiles. A \u003Ccode>type\u003C\u002Fcode> alias doesn&#39;t create a new type — it creates a second name for the same type. \u003Ccode>UserId\u003C\u002Fcode> and \u003Ccode>OrderId\u003C\u002Fcode> both resolve to \u003Ccode>string\u003C\u002Fcode>, so as far as the checker is concerned you wrote \u003Ccode>issueRefund(id: string, ...)\u003C\u002Fcode> twice. The alias documents intent for a human skimming the code; it does nothing for the compiler.\u003C\u002Fp>",{"id":128,"html":129,"text":130,"type":94,"level":31},"b14","The fix: give the type something a plain string doesn&#39;t have","The fix: give the type something a plain string doesn't have",{"id":132,"html":133,"type":84},"b15","\u003Cp>Branded types close the gap by attaching a marker property that exists only in the type system — never at runtime:\u003C\u002Fp>",{"id":135,"code":136,"type":101,"language":102,"highlight":137},"b16","type Brand\u003CT, B extends string> = T & { readonly __brand: B };\n\ntype UserId = Brand\u003Cstring, \"UserId\">;\ntype OrderId = Brand\u003Cstring, \"OrderId\">;\n\nfunction issueRefund(userId: UserId, amountCents: number) { \u002F* ... *\u002F }\n\nfunction toUserId(raw: string): UserId {\n  return raw as UserId;\n}\n\nfunction toOrderId(raw: string): OrderId {\n  return raw as OrderId;\n}",[],{"id":139,"html":140,"type":84},"b17","\u003Cp>Now the swap is a compile error:\u003C\u002Fp>",{"id":142,"code":143,"type":101,"language":102,"highlight":144},"b18","const orderId = toOrderId(\"ord_9f21\");\nissueRefund(orderId, 500);\n\u002F\u002F Argument of type 'OrderId' is not assignable to parameter of type 'UserId'.\n\u002F\u002F Type 'OrderId' is not assignable to type '{ readonly __brand: \"UserId\"; }'.\n\u002F\u002F   Types of property '__brand' are incompatible.\n\u002F\u002F     Type '\"OrderId\"' is not assignable to type '\"UserId\"'.",[],{"id":146,"html":147,"type":84},"b19","\u003Cp>\u003Ccode>UserId\u003C\u002Fcode> and \u003Ccode>OrderId\u003C\u002Fcode> are both still strings underneath — \u003Ccode>__brand\u003C\u002Fcode> never appears in a compiled \u003Ccode>.js\u003C\u002Fcode> file, it&#39;s erased along with every other type annotation. It costs nothing at runtime and nothing in bundle size. All it does is give the structural checker something to disagree about, which is the entire point: you&#39;re opting one specific type out of structural compatibility.\u003C\u002Fp>",{"id":149,"html":150,"type":84},"b20","\u003Cp>The only place you&#39;re allowed to use \u003Ccode>as UserId\u003C\u002Fcode> is inside \u003Ccode>toUserId\u003C\u002Fcode> itself — a narrow, named boundary function. Every other call site just passes a \u003Ccode>UserId\u003C\u002Fcode> it already has, the same way you&#39;d never cast to \u003Ccode>string\u003C\u002Fcode> by hand in normal code.\u003C\u002Fp>",{"id":152,"html":153,"text":154,"type":94,"level":31},"b21","The part branding doesn&#39;t do for you","The part branding doesn't do for you",{"id":156,"html":157,"type":84},"b22","\u003Cp>This is the honest caveat, and skipping it is how teams get a false sense of safety: \u003Cstrong>a brand is a label, not a check.\u003C\u002Fstrong> \u003Ccode>toUserId(&quot;literally anything&quot;)\u003C\u002Fcode> will happily mint a \u003Ccode>UserId\u003C\u002Fcode> out of a string that was never looked up anywhere. Branding stops a \u003Cem>valid\u003C\u002Fem> \u003Ccode>OrderId\u003C\u002Fcode> from sneaking into a \u003Ccode>UserId\u003C\u002Fcode> slot — it does nothing to stop an \u003Cem>invalid\u003C\u002Fem> string from becoming either one.\u003C\u002Fp>",{"id":159,"html":160,"type":84},"b23","\u003Cp>If you need the value validated too, put a real check inside the boundary function instead of a bare cast:\u003C\u002Fp>",{"id":162,"code":163,"type":101,"language":102,"highlight":164},"b24","function toUserId(raw: string): UserId {\n  if (!\u002F^usr_[a-z0-9]+$\u002F.test(raw)) {\n    throw new Error(`not a valid user id: ${raw}`);\n  }\n  return raw as UserId;\n}",[],{"id":166,"html":167,"type":84},"b25","\u003Cp>If you&#39;re already on a validation library, you likely don&#39;t need \u003Ccode>Brand&lt;&gt;\u003C\u002Fcode> yourself — Zod&#39;s \u003Ccode>.brand()\u003C\u002Fcode> does the same type-level trick and ties it to an actual runtime parse: \u003Ccode>z.string().brand&lt;&quot;UserId&quot;&gt;()\u003C\u002Fcode> gives you a \u003Ccode>UserId\u003C\u002Fcode> only after the string has actually been validated. Reach for the hand-rolled version above when you&#39;re branding something you already trust (a value straight out of your own database row), and a validation library&#39;s version when the string is coming from outside — a request body, a query param, a pasted ID in a support ticket.\u003C\u002Fp>",{"id":169,"html":170,"text":170,"type":94,"level":31},"b26","What you get for it",{"id":172,"html":173,"type":84},"b27","\u003Cp>One type error at the call site instead of a wrong refund in production. No new runtime cost — the brand is erased at compile time like every other TypeScript annotation. No new dependency, if you don&#39;t want one. And it generalizes past IDs: money as \u003Ccode>Brand&lt;number, &quot;Cents&quot;&gt;\u003C\u002Fcode> so you can&#39;t add dollars to cents, \u003Ccode>Brand&lt;string, &quot;SanitizedHtml&quot;&gt;\u003C\u002Fcode> so raw user input can&#39;t reach \u003Ccode>dangerouslySetInnerHTML\u003C\u002Fcode> without passing through your sanitizer first, anywhere &quot;same shape, different meaning&quot; is the actual bug waiting to happen.\u003C\u002Fp>",{"id":175,"html":176,"type":84},"b28","\u003Cp>The support engineer in the opening scene didn&#39;t do anything wrong. The types just never told them \u003Ccode>userId\u003C\u002Fcode> and \u003Ccode>orderId\u003C\u002Fcode> were different promises. Now they do.\u003C\u002Fp>",{"id":178,"html":179,"type":84},"b29","\u003C!-- playground:start -->",{"id":181,"html":182,"text":182,"type":94,"level":31},"b30","🎮 Try it yourself",{"id":184,"html":185,"type":84},"b31","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-branded-types-nominal-typing\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":187,"html":188,"type":84},"b32","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":190,"html":191,"type":84},"b33","\u003C!-- playground:end -->",{"id":193,"html":194,"type":84},"b34","\u003C!-- quiz:start -->",{"id":196,"html":197,"text":197,"type":94,"level":31},"b35","🧠 Test yourself",{"id":199,"html":200,"type":84},"b36","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-branded-types-nominal-typing\u002Fquiz\">Take the 7-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":202,"html":203,"type":84},"b37","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":205,"html":206,"type":84},"b38","\u003C!-- quiz:end -->",{"id":208,"html":209,"type":84},"b39","\u003Cp>Where else in your codebase are two meanings hiding behind one primitive type? Money amounts in different currencies? Sanitized vs. raw strings? Drop the pair in the comments — I&#39;ll bet at least one of them has shipped a swap bug already.\u003C\u002Fp>",{"id":211,"html":212,"type":84},"b40","\u003C!-- related:start -->",{"id":214,"html":215,"text":215,"type":94,"level":31},"b41","📚 Read next",{"id":217,"type":218,"items":219,"ordered":18},"b42","list",[220,221,222],"\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-as-const-assertions\">My Reducer&#39;s Switch Stopped Being Exhaustive. \u003Ccode>as const\u003C\u002Fcode> Fixed It.\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fintl-numberformat-currency-formatting\">Stop Formatting Currency With Regex. \u003Ccode>Intl.NumberFormat\u003C\u002Fcode> Does It.\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finferred-type-predicates-filter-boolean\">Inferred Type Predicates Won&#39;t Save filter(Boolean). Here&#39;s What Will.\u003C\u002Fa>",{"id":224,"html":225,"type":84},"b43","\u003C!-- related:end -->",{"id":227,"type":228},"b44","divider",{"id":230,"html":231,"type":84},"b45","\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":233,"html":234,"type":84},"b46","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":236,"type":218,"items":237,"ordered":18},"b47",[238,239,240],"⭐ \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>","A support engineer is looking at a refund ticket. They copy an ID from one browser tab, paste it into another, and call `issueRefund(id)`. The function signature says `id: string`. The ID they pasted is a `string`. TypeScript has nothing to say about it.\n\nThe refund goes out. Just not to the customer who filed the ticket — to whoever that ID actually belonged to.\n\nNobody wrote a bug here. The types were never wrong. That's the part that should bother you.\n\n## Two IDs, one type, zero complaints\n\nHere's the function, trimmed to the part that matters:\n\n```ts\nfunction issueRefund(userId: string, amountCents: number) {\n  \u002F\u002F looks up the user, credits their account\n}\n\nfunction getOrder(orderId: string) {\n  \u002F\u002F fetches the order\n}\n\nconst order = getOrder(\"ord_9f21\");\nissueRefund(order.customerOrderId, 500); \u002F\u002F ord_9f21, not a user id\n```\n\nThat last line compiles clean. `order.customerOrderId` is a `string`. `issueRefund` wants a `string`. TypeScript checks shapes, not names — to the compiler, `UserId` and `OrderId` were never distinct in the first place, because nobody declared them. They're both just `string`, and every `string` is interchangeable with every other `string`.\n\nThis is structural typing, and 95% of the time it's exactly what you want — it's why you can pass a plain object literal anywhere an interface is expected without extending anything. The 5% is IDs, currency amounts, sanitized vs. raw HTML, and anything else where the *shape* is identical but the *meaning* isn't allowed to mix.\n\nSpot where you'd make this mistake yourself? Rename the variables and it's not obvious at all — which is exactly why it ships.\n\n## Why `type UserId = string` doesn't help\n\nThe first instinct is a type alias:\n\n```ts\ntype UserId = string;\ntype OrderId = string;\n\nfunction issueRefund(userId: UserId, amountCents: number) { \u002F* ... *\u002F }\n\nconst orderId: OrderId = \"ord_9f21\";\nissueRefund(orderId, 500); \u002F\u002F still compiles\n```\n\nStill compiles. A `type` alias doesn't create a new type — it creates a second name for the same type. `UserId` and `OrderId` both resolve to `string`, so as far as the checker is concerned you wrote `issueRefund(id: string, ...)` twice. The alias documents intent for a human skimming the code; it does nothing for the compiler.\n\n## The fix: give the type something a plain string doesn't have\n\nBranded types close the gap by attaching a marker property that exists only in the type system — never at runtime:\n\n```ts\ntype Brand\u003CT, B extends string> = T & { readonly __brand: B };\n\ntype UserId = Brand\u003Cstring, \"UserId\">;\ntype OrderId = Brand\u003Cstring, \"OrderId\">;\n\nfunction issueRefund(userId: UserId, amountCents: number) { \u002F* ... *\u002F }\n\nfunction toUserId(raw: string): UserId {\n  return raw as UserId;\n}\n\nfunction toOrderId(raw: string): OrderId {\n  return raw as OrderId;\n}\n```\n\nNow the swap is a compile error:\n\n```ts\nconst orderId = toOrderId(\"ord_9f21\");\nissueRefund(orderId, 500);\n\u002F\u002F Argument of type 'OrderId' is not assignable to parameter of type 'UserId'.\n\u002F\u002F Type 'OrderId' is not assignable to type '{ readonly __brand: \"UserId\"; }'.\n\u002F\u002F   Types of property '__brand' are incompatible.\n\u002F\u002F     Type '\"OrderId\"' is not assignable to type '\"UserId\"'.\n```\n\n`UserId` and `OrderId` are both still strings underneath — `__brand` never appears in a compiled `.js` file, it's erased along with every other type annotation. It costs nothing at runtime and nothing in bundle size. All it does is give the structural checker something to disagree about, which is the entire point: you're opting one specific type out of structural compatibility.\n\nThe only place you're allowed to use `as UserId` is inside `toUserId` itself — a narrow, named boundary function. Every other call site just passes a `UserId` it already has, the same way you'd never cast to `string` by hand in normal code.\n\n## The part branding doesn't do for you\n\nThis is the honest caveat, and skipping it is how teams get a false sense of safety: **a brand is a label, not a check.** `toUserId(\"literally anything\")` will happily mint a `UserId` out of a string that was never looked up anywhere. Branding stops a *valid* `OrderId` from sneaking into a `UserId` slot — it does nothing to stop an *invalid* string from becoming either one.\n\nIf you need the value validated too, put a real check inside the boundary function instead of a bare cast:\n\n```ts\nfunction toUserId(raw: string): UserId {\n  if (!\u002F^usr_[a-z0-9]+$\u002F.test(raw)) {\n    throw new Error(`not a valid user id: ${raw}`);\n  }\n  return raw as UserId;\n}\n```\n\nIf you're already on a validation library, you likely don't need `Brand\u003C>` yourself — Zod's `.brand()` does the same type-level trick and ties it to an actual runtime parse: `z.string().brand\u003C\"UserId\">()` gives you a `UserId` only after the string has actually been validated. Reach for the hand-rolled version above when you're branding something you already trust (a value straight out of your own database row), and a validation library's version when the string is coming from outside — a request body, a query param, a pasted ID in a support ticket.\n\n## What you get for it\n\nOne type error at the call site instead of a wrong refund in production. No new runtime cost — the brand is erased at compile time like every other TypeScript annotation. No new dependency, if you don't want one. And it generalizes past IDs: money as `Brand\u003Cnumber, \"Cents\">` so you can't add dollars to cents, `Brand\u003Cstring, \"SanitizedHtml\">` so raw user input can't reach `dangerouslySetInnerHTML` without passing through your sanitizer first, anywhere \"same shape, different meaning\" is the actual bug waiting to happen.\n\nThe support engineer in the opening scene didn't do anything wrong. The types just never told them `userId` and `orderId` were different promises. Now they do.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-branded-types-nominal-typing\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 7-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-branded-types-nominal-typing\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\nWhere else in your codebase are two meanings hiding behind one primitive type? Money amounts in different currencies? Sanitized vs. raw strings? Drop the pair in the comments — I'll bet at least one of them has shipped a swap bug already.\n\n\u003C!-- related:start -->\n\n## 📚 Read next\n\n- [My Reducer's Switch Stopped Being Exhaustive. `as const` Fixed It.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-as-const-assertions)\n- [Stop Formatting Currency With Regex. `Intl.NumberFormat` Does It.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fintl-numberformat-currency-formatting)\n- [Inferred Type Predicates Won't Save filter(Boolean). Here's What Will.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finferred-type-predicates-filter-boolean)\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":243,"description":49},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-branded-types-nominal-typing","01a1fce0-bedd-7648-b22e-4d4c57f8ff91",{"id":246,"locked":18},"01a1fce0-bf4f-70f6-bd12-4aec4228ef2d",[248],{"id":249,"slug":46,"title":250,"_count":251},"01a1fce0-bf6a-70d9-a5b6-e99c1eb59f3e","Branded types",{"questions":252},7,[254],{"locale":13,"slug":46},{"id":249,"slug":46,"title":250,"_count":256,"questionCount":252},{"questions":252},[],[259,261,263,267,271,275,277,281,283,287,291,295],{"slug":70,"name":71,"articles":260},195,{"slug":67,"name":68,"articles":262},156,{"slug":264,"name":265,"articles":266},"frontend","Frontend",103,{"slug":268,"name":269,"articles":270},"tutorial","Tutorial",85,{"slug":272,"name":273,"articles":274},"css","Css",56,{"slug":61,"name":65,"articles":276},36,{"slug":278,"name":279,"articles":280},"performance","Performance",33,{"slug":73,"name":74,"articles":282},26,{"slug":284,"name":285,"articles":286},"react","React",23,{"slug":288,"name":289,"articles":290},"node","Node",19,{"slug":292,"name":293,"articles":294},"browser","Browser",18,{"slug":296,"name":297,"articles":298},"nextjs","Nextjs",13,{"items":300,"meta":423},[301,320,339,351,369,389,406],{"id":302,"slug":303,"title":304,"subtitle":48,"excerpt":305,"coverUrl":306,"locale":13,"readingMinutes":307,"publishedAt":308,"viewCount":309,"likeCount":19,"commentCount":19,"author":310,"vertical":311,"topic":312,"tags":313,"_count":318,"playground":319,"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",25,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[314,315,316,317],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":268,"name":269,"color":48},{"assessments":76},{"slug":303},{"id":321,"slug":322,"title":323,"subtitle":48,"excerpt":324,"coverUrl":325,"locale":13,"readingMinutes":326,"publishedAt":327,"viewCount":328,"likeCount":19,"commentCount":19,"author":329,"vertical":330,"topic":331,"tags":332,"_count":337,"playground":338,"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},[333,334,335,336],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":268,"name":269,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":322},{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":340,"likeCount":19,"commentCount":19,"author":341,"vertical":342,"topic":343,"tags":344,"_count":349,"playground":350,"hasQuiz":17,"hasPlayground":17},11,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[345,346,347,348],{"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":352,"slug":353,"title":354,"subtitle":48,"excerpt":355,"coverUrl":356,"locale":13,"readingMinutes":51,"publishedAt":357,"viewCount":358,"likeCount":19,"commentCount":19,"author":359,"vertical":360,"topic":361,"tags":362,"_count":367,"playground":368,"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},[363,364,365,366],{"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":353},{"id":370,"slug":371,"title":372,"subtitle":48,"excerpt":373,"coverUrl":374,"locale":13,"readingMinutes":375,"publishedAt":376,"viewCount":358,"likeCount":19,"commentCount":19,"author":377,"vertical":378,"topic":379,"tags":382,"_count":387,"playground":388,"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":380,"name":381},"nestjs","Nestjs",[383,384,385,386],{"slug":380,"name":381,"color":48},{"slug":288,"name":289,"color":48},{"slug":61,"name":65,"color":48},{"slug":268,"name":269,"color":48},{"assessments":76},{"slug":371},{"id":390,"slug":391,"title":392,"subtitle":48,"excerpt":393,"coverUrl":394,"locale":13,"readingMinutes":51,"publishedAt":395,"viewCount":31,"likeCount":19,"commentCount":19,"author":396,"vertical":397,"topic":398,"tags":399,"_count":404,"playground":405,"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},[400,401,402,403],{"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":391},{"id":407,"slug":408,"title":409,"subtitle":48,"excerpt":410,"coverUrl":411,"locale":13,"readingMinutes":51,"publishedAt":412,"viewCount":31,"likeCount":19,"commentCount":19,"author":413,"vertical":414,"topic":415,"tags":416,"_count":421,"playground":422,"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},[417,418,419,420],{"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":408},{"page":76,"perPage":252,"total":276,"totalPages":307},"\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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>userId\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> amountCents\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F looks up the user, credits their account\n\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">getOrder\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>orderId\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F fetches the order\n\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> order \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">getOrder\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"ord_9f21\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>order\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>customerOrderId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">500\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F ord_9f21, not a user id\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\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> string;\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">OrderId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> string;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>userId\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> amountCents\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> \u003Cspan class=\"shj-cmnt\">\u002F* ... *\u002F\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> orderId\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">OrderId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"ord_9f21\"\u003C\u002Fspan>;\n\u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>orderId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">500\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>; \u003Cspan class=\"shj-cmnt\">\u002F\u002F still compiles\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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Brand\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\">B\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\">T\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">&#38;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">readonly\u003C\u002Fspan> __brand\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">B\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Brand\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>string\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"UserId\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-kwd\">type\u003C\u002Fspan> \u003Cspan class=\"shj-class\">OrderId\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Brand\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>string\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"OrderId\"\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>userId\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> amountCents\u003Cspan class=\"shj-type\">: number\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> \u003Cspan class=\"shj-cmnt\">\u002F* ... *\u002F\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">toUserId\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>raw\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> raw \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">toOrderId\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>raw\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">OrderId\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> raw \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">OrderId\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>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> orderId \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">toOrderId\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"ord_9f21\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-func\">issueRefund\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>orderId\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">500\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F Argument of type 'OrderId' is not assignable to parameter of type 'UserId'.\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F Type 'OrderId' is not assignable to type '{ readonly __brand: \"UserId\"; }'.\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F   Types of property '__brand' are incompatible.\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F     Type '\"OrderId\"' is not assignable to type '\"UserId\"'.\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\">function\u003C\u002Fspan> \u003Cspan class=\"shj-func\">toUserId\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>raw\u003Cspan class=\"shj-type\">: string\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">if\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">!\u002F^\u003C\u002Fspan>usr_\u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>a\u003Cspan class=\"shj-oper\">-\u003C\u002Fspan>z0\u003Cspan class=\"shj-oper\">-\u003C\u002Fspan>\u003Cspan class=\"shj-num\">9\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">+\u003C\u002Fspan>$\u003Cspan class=\"shj-oper\">\u002F.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">test\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>raw\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">throw\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">new\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Error\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">`not a valid user id: \u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">${\u003C\u002Fspan>raw\u003Cspan class=\"shj-kwd\">}\u003C\u002Fspan>\u003Cspan class=\"shj-str\">`\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> raw \u003Cspan class=\"shj-kwd\">as\u003C\u002Fspan> \u003Cspan class=\"shj-class\">UserId\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":430},[]]