[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"quiz-typescript-noinfer-generic-widening":44,"quiz-article-typescript-noinfer-generic-widening":60,"search-suggestions":270,"path-membership-typescript-noinfer-generic-widening":311},[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,"kind":47,"title":48,"description":49,"config":50,"verticalId":5,"vertical":55,"course":52,"_count":56,"access":57,"attempts":59,"questionCount":51},"01a1df1b-3346-75f8-aade-c7a60df4513c","typescript-noinfer-generic-widening","PRACTICE_QUIZ","NoInfer\u003CT> Quiz","Check whether the inference-widening bug and the NoInfer\u003CT> fix actually stuck — what it changes, what it doesn't, and why one parameter still has to vote.",{"questionCount":51,"timeLimitSec":52,"shuffleQuestions":18,"shuffleOptions":17,"negativeMarking":19,"passScorePct":53,"maxAttempts":52,"revealAnswers":54,"allowFlagging":18,"allowBacktracking":17},8,null,70,"AFTER_SUBMIT",{"slug":6,"name":7},{"questions":51},{"allowed":17,"reason":58},"FREE",[],{"id":61,"slug":46,"title":62,"subtitle":52,"excerpt":63,"coverUrl":64,"locale":13,"readingMinutes":65,"publishedAt":66,"viewCount":67,"likeCount":19,"commentCount":19,"author":68,"vertical":73,"topic":74,"tags":77,"_count":89,"playground":91,"body":93,"bodyMd":257,"seo":258,"translationGroupId":260,"series":52,"podcastUrl":52,"verticalId":5,"thread":261,"assessments":263,"translations":266,"quiz":268},"01a1df1b-32db-7638-a86f-5cea99530919","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",5,"2026-11-27T11:45:27.674Z",11,{"id":69,"name":70,"username":71,"avatarUrl":52,"headline":72},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":75,"name":76},"typescript","TypeScript",[78,80,83,86],{"slug":75,"name":79,"color":52},"Typescript",{"slug":81,"name":82,"color":52},"javascript","Javascript",{"slug":84,"name":85,"color":52},"programming","Programming",{"slug":87,"name":88,"color":52},"webdev","Webdev",{"assessments":90},1,{"slug":46,"title":92},"NoInfer&lt;T&gt; — interactive playground",{"blocks":94,"version":90},[95,99,105,108,111,114,118,121,125,128,131,135,138,141,144,147,151,154,157,160,163,166,169,173,176,180,183,186,189,193,196,199,202,205,208,211,214,217,220,223,226,229,232,239,242,245,248,251],{"id":96,"html":97,"type":98},"b1","\u003Cp>Someone on the team adds a new feature flag, wires up its default, and opens a PR:\u003C\u002Fp>","paragraph",{"id":100,"code":101,"type":102,"language":103,"highlight":104},"b2","defineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");","code","ts",[],{"id":106,"html":107,"type":98},"b3","\u003Cp>One lowercase \u003Ccode>m\u003C\u002Fcode>. Nobody catches it in review — the build is green, the editor shows no red squiggle, \u003Ccode>defineFlags\u003C\u002Fcode> is fully generic and type-safe by every measure anyone checked. It merges.\u003C\u002Fp>",{"id":109,"html":110,"type":98},"b4","\u003Cp>Three days later the settings panel that reads this default renders a blank icon, because the lookup table keyed by flag name has no entry for \u003Ccode>&quot;darkmode&quot;\u003C\u002Fcode> — only \u003Ccode>&quot;darkMode&quot;\u003C\u002Fcode>. The function whose entire job was to make this exact typo impossible let it straight through, silently.\u003C\u002Fp>",{"id":112,"html":113,"type":98},"b5","\u003Cp>The fix is one word. Understanding why TypeScript needed it took longer.\u003C\u002Fp>",{"id":115,"html":116,"text":116,"type":117,"level":31},"b6","The function looked airtight","heading",{"id":119,"html":120,"type":98},"b7","\u003Cp>Here&#39;s roughly what \u003Ccode>defineFlags\u003C\u002Fcode> looked like:\u003C\u002Fp>",{"id":122,"code":123,"type":102,"language":103,"highlight":124},"b8","function defineFlags\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: Name\n) {\n  return { names, defaultFlag };\n}",[],{"id":126,"html":127,"type":98},"b9","\u003Cp>This reads like it should be bulletproof. \u003Ccode>Name\u003C\u002Fcode> is inferred from the array you pass in, so \u003Ccode>defaultFlag\u003C\u002Fcode> has to be one of those exact strings — that&#39;s the whole point of writing it generic instead of typing both parameters as \u003Ccode>string\u003C\u002Fcode>.\u003C\u002Fp>",{"id":129,"html":130,"type":98},"b10","\u003Cp>Spot the bug yet? Try it before you scroll: paste this into a \u003Ccode>.ts\u003C\u002Fcode> file and see what the compiler says.\u003C\u002Fp>",{"id":132,"code":133,"type":102,"language":103,"highlight":134},"b11","defineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"newCheckout\"); \u002F\u002F fine\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");    \u002F\u002F ???",[],{"id":136,"html":137,"type":98},"b12","\u003Cp>Zero errors. Both lines. The second one — the typo — compiles exactly as cleanly as the first.\u003C\u002Fp>",{"id":139,"html":140,"text":140,"type":117,"level":31},"b13","What TypeScript was actually inferring",{"id":142,"html":143,"type":98},"b14","\u003Cp>Here&#39;s the part that&#39;s easy to get wrong: TypeScript doesn&#39;t treat the array argument as &quot;the source of truth&quot; for \u003Ccode>Name\u003C\u002Fcode> and then check \u003Ccode>defaultFlag\u003C\u002Fcode> against it. It collects a \u003Cem>candidate\u003C\u002Fem> type from every position where \u003Ccode>Name\u003C\u002Fcode> appears unannotated, across the whole call, and only then decides what \u003Ccode>Name\u003C\u002Fcode> is.\u003C\u002Fp>",{"id":145,"html":146,"type":98},"b15","\u003Cp>\u003Ccode>names\u003C\u002Fcode> offers \u003Ccode>&quot;darkMode&quot; | &quot;newCheckout&quot; | &quot;betaSearch&quot;\u003C\u002Fcode> as a candidate. \u003Ccode>defaultFlag\u003C\u002Fcode> offers whatever you passed — including \u003Ccode>&quot;darkmode&quot;\u003C\u002Fcode> — as another candidate. TypeScript doesn&#39;t pick one and validate the other against it. It unions them. \u003Ccode>Name\u003C\u002Fcode> quietly becomes \u003Ccode>&quot;darkMode&quot; | &quot;newCheckout&quot; | &quot;betaSearch&quot; | &quot;darkmode&quot;\u003C\u002Fcode>, and under that definition, passing \u003Ccode>&quot;darkmode&quot;\u003C\u002Fcode> for a parameter of type \u003Ccode>Name\u003C\u002Fcode> is completely correct. You can watch it happen by forcing the inferred type into the open:\u003C\u002Fp>",{"id":148,"code":149,"type":102,"language":103,"highlight":150},"b16","function defineFlagsTyped\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: Name\n): Name {\n  return names[0] as Name;\n}\n\nconst result = defineFlagsTyped(\n  [\"darkMode\", \"newCheckout\", \"betaSearch\"],\n  \"darkmode\"\n);\n\n\u002F\u002F Assigning the \"real\" union back reveals what Name actually became:\nconst check: \"darkMode\" | \"newCheckout\" | \"betaSearch\" = result;\n\u002F\u002F Type '\"darkMode\" | \"newCheckout\" | \"betaSearch\" | \"darkmode\"'\n\u002F\u002F is not assignable to type '\"darkMode\" | \"newCheckout\" | \"betaSearch\"'.",[],{"id":152,"html":153,"type":98},"b17","\u003Cp>\u003Ccode>Name\u003C\u002Fcode> picked up a fourth member nobody asked for. The typo isn&#39;t a value that failed a check — it&#39;s part of the type now.\u003C\u002Fp>",{"id":155,"html":156,"type":98},"b18","\u003C!-- playground:start -->",{"id":158,"html":159,"text":159,"type":117,"level":31},"b19","🎮 Try it yourself",{"id":161,"html":162,"type":98},"b20","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-noinfer-generic-widening\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":164,"html":165,"type":98},"b21","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":167,"html":168,"type":98},"b22","\u003C!-- playground:end -->",{"id":170,"html":171,"text":172,"type":117,"level":31},"b23","The fix: tell TypeScript which position doesn&#39;t get a vote","The fix: tell TypeScript which position doesn't get a vote",{"id":174,"html":175,"type":98},"b24","\u003Cp>\u003Ccode>defaultFlag\u003C\u002Fcode> was never supposed to help decide what \u003Ccode>Name\u003C\u002Fcode> is. It was supposed to be checked \u003Cem>against\u003C\u002Fem> a \u003Ccode>Name\u003C\u002Fcode> that the array had already settled. That&#39;s exactly what \u003Ccode>NoInfer&lt;T&gt;\u003C\u002Fcode> — built into TypeScript&#39;s standard library since 5.4 — exists to say:\u003C\u002Fp>",{"id":177,"code":178,"type":102,"language":103,"highlight":179},"b25","function defineFlags\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: NoInfer\u003CName>\n) {\n  return { names, defaultFlag };\n}\n\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"newCheckout\"); \u002F\u002F fine\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");\n\u002F\u002F Argument of type '\"darkmode\"' is not assignable to parameter of type\n\u002F\u002F '\"darkMode\" | \"newCheckout\" | \"betaSearch\" | undefined'.",[],{"id":181,"html":182,"type":98},"b26","\u003Cp>Same call, same arguments — now the typo is a compile error, pointing at the exact argument, before the PR even opens.\u003C\u002Fp>",{"id":184,"html":185,"type":98},"b27","\u003Cp>\u003Ccode>NoInfer&lt;T&gt;\u003C\u002Fcode> doesn&#39;t change what \u003Ccode>Name\u003C\u002Fcode> \u003Cem>can\u003C\u002Fem> be; it changes who gets to decide. Wrapping a position in it removes that position from the pool of candidates TypeScript draws \u003Ccode>Name\u003C\u002Fcode> from, without removing the requirement that whatever you pass there still has to match. \u003Ccode>names\u003C\u002Fcode> is still the only thing allowed to say what \u003Ccode>Name\u003C\u002Fcode> is. \u003Ccode>defaultFlag\u003C\u002Fcode> has to agree with it, not contribute to it.\u003C\u002Fp>",{"id":187,"html":188,"type":98},"b28","\u003Cp>It&#39;s a type-only change — nothing about the function&#39;s runtime behavior moves. You&#39;re only narrowing which arguments count as evidence to the type checker.\u003C\u002Fp>",{"id":190,"html":191,"text":192,"type":117,"level":31},"b29","Where it won&#39;t save you","Where it won't save you",{"id":194,"html":195,"type":98},"b30","\u003Cp>\u003Ccode>NoInfer&lt;T&gt;\u003C\u002Fcode> only works at compile time, against types TypeScript can actually see. A typed value — even a plain \u003Ccode>string | undefined\u003C\u002Fcode> from \u003Ccode>process.env\u003C\u002Fcode> — still gets checked against the real \u003Ccode>Name\u003C\u002Fcode> and still gets rejected if it&#39;s wrong. The gap is narrower than &quot;anything not a literal&quot;: it&#39;s specifically \u003Ccode>any\u003C\u002Fcode>. \u003Ccode>JSON.parse()\u003C\u002Fcode> returns \u003Ccode>any\u003C\u002Fcode> by definition, and \u003Ccode>any\u003C\u002Fcode> bypasses every check in the type system, \u003Ccode>NoInfer\u003C\u002Fcode> included — \u003Ccode>defineFlags([...], JSON.parse(rawConfig))\u003C\u002Fcode> compiles clean no matter what string ends up inside it. You still need a runtime check (or a schema validator) at the edge where \u003Ccode>any\u003C\u002Fcode>-typed data enters your program.\u003C\u002Fp>",{"id":197,"html":198,"type":98},"b31","\u003Cp>It also needs TypeScript 5.4 or newer — it shipped in March 2024 as a real compiler intrinsic (\u003Ccode>type NoInfer&lt;T&gt; = intrinsic\u003C\u002Fcode>), not a type you could write yourself. Before 5.4, people approximated it with a conditional-type trick (\u003Ccode>type NoInfer&lt;T&gt; = [T][T extends any ? 0 : never]\u003C\u002Fcode>), which worked in simple cases but had edge-case bugs the built-in version doesn&#39;t share. If you&#39;re on an older compiler, that trick is a stopgap — upgrading is the real fix.\u003C\u002Fp>",{"id":200,"html":201,"type":98},"b32","\u003Cp>And it won&#39;t flag a parameter you \u003Cem>forgot\u003C\u002Fem> to mark — this is opt-in, function by function. It fixes the position you wrap, not every generic helper in your codebase that has the same shape.\u003C\u002Fp>",{"id":203,"html":204,"text":204,"type":117,"level":31},"b33","The takeaway",{"id":206,"html":207,"type":98},"b34","\u003Cp>Any generic helper with a &quot;default,&quot; a &quot;fallback,&quot; or a &quot;this has to match&quot; parameter sitting next to the argument that actually defines the type is a candidate for this bug — it&#39;s letting a position vote that should only ever be checked. The fix is wrapping it in \u003Ccode>NoInfer&lt;T&gt;\u003C\u002Fcode>, and it&#39;s safe to add retroactively: it only makes previously-accepted typos start failing, nothing that was correct before stops compiling.\u003C\u002Fp>",{"id":209,"html":210,"type":98},"b35","\u003Cp>Go find one of those helpers in your own codebase — a config builder, a reducer map, an event registry — and check whether its &quot;default&quot; parameter is quietly widening instead of being validated. What did you find?\u003C\u002Fp>",{"id":212,"html":213,"type":98},"b36","\u003C!-- quiz:start -->",{"id":215,"html":216,"text":216,"type":117,"level":31},"b37","🧠 Test yourself",{"id":218,"html":219,"type":98},"b38","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-noinfer-generic-widening\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":221,"html":222,"type":98},"b39","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":224,"html":225,"type":98},"b40","\u003C!-- quiz:end -->",{"id":227,"html":228,"type":98},"b41","\u003C!-- related:start -->",{"id":230,"html":231,"text":231,"type":117,"level":31},"b42","📚 Read next",{"id":233,"type":234,"items":235,"ordered":18},"b43","list",[236,237,238],"\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\u002Ftypescript-satisfies-operator\">Your TypeScript config objects are losing type information. \u003Ccode>satisfies\u003C\u002Fcode> fixes it.\u003C\u002Fa>",{"id":240,"html":241,"type":98},"b44","\u003C!-- related:end -->",{"id":243,"type":244},"b45","divider",{"id":246,"html":247,"type":98},"b46","\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":249,"html":250,"type":98},"b47","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":252,"type":234,"items":253,"ordered":18},"b48",[254,255,256],"⭐ \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>","Someone on the team adds a new feature flag, wires up its default, and opens a PR:\n\n```ts\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");\n```\n\nOne lowercase `m`. Nobody catches it in review — the build is green, the editor shows no red squiggle, `defineFlags` is fully generic and type-safe by every measure anyone checked. It merges.\n\nThree days later the settings panel that reads this default renders a blank icon, because the lookup table keyed by flag name has no entry for `\"darkmode\"` — only `\"darkMode\"`. The function whose entire job was to make this exact typo impossible let it straight through, silently.\n\nThe fix is one word. Understanding why TypeScript needed it took longer.\n\n## The function looked airtight\n\nHere's roughly what `defineFlags` looked like:\n\n```ts\nfunction defineFlags\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: Name\n) {\n  return { names, defaultFlag };\n}\n```\n\nThis reads like it should be bulletproof. `Name` is inferred from the array you pass in, so `defaultFlag` has to be one of those exact strings — that's the whole point of writing it generic instead of typing both parameters as `string`.\n\nSpot the bug yet? Try it before you scroll: paste this into a `.ts` file and see what the compiler says.\n\n```ts\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"newCheckout\"); \u002F\u002F fine\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");    \u002F\u002F ???\n```\n\nZero errors. Both lines. The second one — the typo — compiles exactly as cleanly as the first.\n\n## What TypeScript was actually inferring\n\nHere's the part that's easy to get wrong: TypeScript doesn't treat the array argument as \"the source of truth\" for `Name` and then check `defaultFlag` against it. It collects a *candidate* type from every position where `Name` appears unannotated, across the whole call, and only then decides what `Name` is.\n\n`names` offers `\"darkMode\" | \"newCheckout\" | \"betaSearch\"` as a candidate. `defaultFlag` offers whatever you passed — including `\"darkmode\"` — as another candidate. TypeScript doesn't pick one and validate the other against it. It unions them. `Name` quietly becomes `\"darkMode\" | \"newCheckout\" | \"betaSearch\" | \"darkmode\"`, and under that definition, passing `\"darkmode\"` for a parameter of type `Name` is completely correct. You can watch it happen by forcing the inferred type into the open:\n\n```ts\nfunction defineFlagsTyped\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: Name\n): Name {\n  return names[0] as Name;\n}\n\nconst result = defineFlagsTyped(\n  [\"darkMode\", \"newCheckout\", \"betaSearch\"],\n  \"darkmode\"\n);\n\n\u002F\u002F Assigning the \"real\" union back reveals what Name actually became:\nconst check: \"darkMode\" | \"newCheckout\" | \"betaSearch\" = result;\n\u002F\u002F Type '\"darkMode\" | \"newCheckout\" | \"betaSearch\" | \"darkmode\"'\n\u002F\u002F is not assignable to type '\"darkMode\" | \"newCheckout\" | \"betaSearch\"'.\n```\n\n`Name` picked up a fourth member nobody asked for. The typo isn't a value that failed a check — it's part of the type now.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-noinfer-generic-widening\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## The fix: tell TypeScript which position doesn't get a vote\n\n`defaultFlag` was never supposed to help decide what `Name` is. It was supposed to be checked *against* a `Name` that the array had already settled. That's exactly what `NoInfer\u003CT>` — built into TypeScript's standard library since 5.4 — exists to say:\n\n```ts\nfunction defineFlags\u003CName extends string>(\n  names: Name[],\n  defaultFlag?: NoInfer\u003CName>\n) {\n  return { names, defaultFlag };\n}\n\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"newCheckout\"); \u002F\u002F fine\ndefineFlags([\"darkMode\", \"newCheckout\", \"betaSearch\"], \"darkmode\");\n\u002F\u002F Argument of type '\"darkmode\"' is not assignable to parameter of type\n\u002F\u002F '\"darkMode\" | \"newCheckout\" | \"betaSearch\" | undefined'.\n```\n\nSame call, same arguments — now the typo is a compile error, pointing at the exact argument, before the PR even opens.\n\n`NoInfer\u003CT>` doesn't change what `Name` *can* be; it changes who gets to decide. Wrapping a position in it removes that position from the pool of candidates TypeScript draws `Name` from, without removing the requirement that whatever you pass there still has to match. `names` is still the only thing allowed to say what `Name` is. `defaultFlag` has to agree with it, not contribute to it.\n\nIt's a type-only change — nothing about the function's runtime behavior moves. You're only narrowing which arguments count as evidence to the type checker.\n\n## Where it won't save you\n\n`NoInfer\u003CT>` only works at compile time, against types TypeScript can actually see. A typed value — even a plain `string | undefined` from `process.env` — still gets checked against the real `Name` and still gets rejected if it's wrong. The gap is narrower than \"anything not a literal\": it's specifically `any`. `JSON.parse()` returns `any` by definition, and `any` bypasses every check in the type system, `NoInfer` included — `defineFlags([...], JSON.parse(rawConfig))` compiles clean no matter what string ends up inside it. You still need a runtime check (or a schema validator) at the edge where `any`-typed data enters your program.\n\nIt also needs TypeScript 5.4 or newer — it shipped in March 2024 as a real compiler intrinsic (`type NoInfer\u003CT> = intrinsic`), not a type you could write yourself. Before 5.4, people approximated it with a conditional-type trick (`type NoInfer\u003CT> = [T][T extends any ? 0 : never]`), which worked in simple cases but had edge-case bugs the built-in version doesn't share. If you're on an older compiler, that trick is a stopgap — upgrading is the real fix.\n\nAnd it won't flag a parameter you *forgot* to mark — this is opt-in, function by function. It fixes the position you wrap, not every generic helper in your codebase that has the same shape.\n\n## The takeaway\n\nAny generic helper with a \"default,\" a \"fallback,\" or a \"this has to match\" parameter sitting next to the argument that actually defines the type is a candidate for this bug — it's letting a position vote that should only ever be checked. The fix is wrapping it in `NoInfer\u003CT>`, and it's safe to add retroactively: it only makes previously-accepted typos start failing, nothing that was correct before stops compiling.\n\nGo find one of those helpers in your own codebase — a config builder, a reducer map, an event registry — and check whether its \"default\" parameter is quietly widening instead of being validated. What did you find?\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-noinfer-generic-widening\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\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- [Your TypeScript config objects are losing type information. `satisfies` fixes it.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-satisfies-operator)\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":62,"canonical":259,"description":63},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ftypescript-noinfer-generic-widening","01a1df1b-32db-7638-a86f-6132d3f0e26f",{"id":262,"locked":18},"01a1df1b-3323-7396-9bb3-c0c67e0858e1",[264],{"id":45,"slug":46,"title":48,"_count":265},{"questions":51},[267],{"locale":13,"slug":46},{"id":45,"slug":46,"title":48,"_count":269,"questionCount":51},{"questions":51},[271,273,275,279,283,287,289,293,295,299,303,307],{"slug":87,"name":88,"articles":272},195,{"slug":81,"name":82,"articles":274},156,{"slug":276,"name":277,"articles":278},"frontend","Frontend",103,{"slug":280,"name":281,"articles":282},"tutorial","Tutorial",85,{"slug":284,"name":285,"articles":286},"css","Css",56,{"slug":75,"name":79,"articles":288},36,{"slug":290,"name":291,"articles":292},"performance","Performance",33,{"slug":84,"name":85,"articles":294},26,{"slug":296,"name":297,"articles":298},"react","React",23,{"slug":300,"name":301,"articles":302},"node","Node",19,{"slug":304,"name":305,"articles":306},"browser","Browser",18,{"slug":308,"name":309,"articles":310},"nextjs","Nextjs",13,[]]