{"success":true,"name":"typescript-any-is-a-virus-keep-unknown-at-the-border-and-nar","description":"Writing TypeScript and tempted to type something as any to move on","category":"ai-brimind","path":"ai-brimind/typescript-any-is-a-virus-keep-unknown-at-the-border-and-nar/SKILL.md","file":"SKILL.md","content":"---\nname: typescript-any-is-a-virus-keep-unknown-at-the-border-and-nar\ndescription: \"Writing TypeScript and tempted to type something as any to move on\"\n---\n\n# TypeScript any Is a Virus: Keep unknown at the Border and Narrow Explicitly\n\n## When to use\nProject is TypeScript, and you're about to write 'any', see 'any' spreading from an API/JSON boundary, or silence a type error to keep moving.\n\n## Example request\nJSON.parse result typed as any flows through five functions → every one of them loses checking; typing the border as unknown and narrowing once restores safety downstream. — 'any' used to silence one red squiggle → the real bug it was pointing at ships to production; the error was information, not an obstacle. — Function accepts any 'to be flexible' → callers can pass garbage and the compiler stays quiet; generics or union types give flexibility WITH checking. — Data from fetch assumed to match an interface via 'as' → the server changed and nothing warned; runtime validation at the boundary is what actually guarantees the type.\n\n## Instructions\nAct as a quarantine officer who knows one 'any' infects every value it touches downstream. When tempted to write any or you find it spreading: 1) Find the border where untyped data actually enters (fetch, JSON.parse, env vars, third-party libs) — that is the ONE place uncertainty is legitimate. 2) Type that border as unknown, not any: unknown forces you to check before use; any turns the compiler off. 3) Narrow explicitly right there — a type guard, a schema validator, or discriminated-union checks — so everything past the border is genuinely typed, not hopefully typed. 4) If any exists to silence an error, read the error first: classify whether it flags a real bug, a wrong type definition, or a genuinely dynamic case — only the last justifies unknown plus narrowing. 5) Check whether the ecosystem already ships types (bundled types or a types package) before hand-writing declarations. If you can't tell what shape the data really has, log a real sample and look instead of guessing an interface. Only remove or add a type once the actual runtime shape is confirmed, and explain why the fix restores real checking at the border instead of just making the red squiggle disappear.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #961\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}