[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CGH5WQXHY9CBY6Z9RMSNW4":3,"skill-same:01M6CGH5WQXHY9CBY6Z9RMSNW4":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":45,"commitSha":46,"skillDirectory":47,"forksCount":48,"repositoryHtmlUrl":49,"repositoryHomepageUrl":6,"ownerHtmlUrl":50,"ownerBlogUrl":51,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"01M6CGH5WQXHY9CBY6Z9RMSNW4","avoid-widening",null,"Keep a type as narrow as the value it describes. An annotation wider than what inference already knows throws information away, so annotate only to add information. Keep immutable lookup tables literal with `as const satisfies`, type built keys with template literal types and build them `as const`, and widen on purpose only at a boundary where inference is unsound.","MetaMask\u002Fskills","MetaMask","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F11744586?v=4","01M6CGATQAN8ZP8HWEZH2379WJ","01M6CGATVJDE1ZMSRM20CFJ5S8",25,"MIT","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Ftypescript\u002Fskills\u002Favoid-widening\u002Fskill.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"avoid widening","as","value","at","keys","with","information","types","it","keep","annotation","type","inference","annotate","Literal","build","only","template","boundary","immutable","lookup","2026-11-10 10:12:30",false,"---\nname: avoid-widening\ndescription: >-\n  Keep a type as narrow as the value it describes. An annotation wider than\n  what inference already knows throws information away, so annotate only to\n  add information. Keep immutable lookup tables literal with `as const\n  satisfies`, type built keys with template literal types and build them\n  `as const`, and widen on purpose only at a boundary where inference is\n  unsound.\nmaturity: experimental\n---\n\n# Avoid Widening\n\nDeepens `MetaMask\u002Fcontributor-docs` [`docs\u002Ftypescript.md`](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L40-L42), *Avoid unintentionally widening an inferred type with a type annotation*: \"Enforcing a wider type defeats the purpose of adding an explicit type declaration, as it _loses_ type information instead of adding it.\" `derive-types` covers where a type should come from. This skill covers how wide it should be, and `avoid-any` covers the annotation that turns checking off.\n\n## When To Use\n\n- Writing or reviewing a type annotation, a `satisfies` clause or an `as const`.\n- A lookup table maps one set of names to another, such as trace names or action types.\n- A collection is keyed by strings built from known parts, such as `` `${name}:${id}` ``.\n- Proposing a type change in review, where a widening suggestion reads as a tightening.\n\n## Annotate to add information, never to repeat or lose it\n\nCompare the annotation with the type inference already produces. Equal adds nothing, and wider loses information. Only a narrower annotation, or a deliberate widening at a boundary (below), is worth writing.\n\n| declaration | resulting type |\n|---|---|\n| `const name = 'foo'` | `\"foo\"` |\n| `const name: string = 'foo'` | `string`, widened |\n| `const ids = [1, 2] as const` | `readonly [1, 2]` |\n| `const ids: number[] = [1, 2]` | `number[]`, widened |\n\nTo check a value against a type without widening it, use `satisfies` ([`docs\u002Ftypescript.md` L134-L136](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L134-L136)). The exception is a mutable object, array or class that code adds to later. There the narrowest type excludes the additions, so annotate with `:` unless the value is meant to be immutable ([L201-L205](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L201-L205)).\n\n## Keep immutable lookup tables literal\n\n```typescript\n\u002F\u002F ? The annotation widens every value to `TraceName`, so `NAMES[name]` no longer says which member it is.\nconst NAMES: Record\u003CFeatureTraceName, TraceName> = {\n  'Feature Open': TraceName.FeatureOpen,\n  'Feature Close': TraceName.FeatureClose,\n};\n\n\u002F\u002F ✅ Checks every key and value, keeps each value's member type, and makes the table read-only.\nconst NAMES = {\n  'Feature Open': TraceName.FeatureOpen,\n  'Feature Close': TraceName.FeatureClose,\n} as const satisfies Record\u003CFeatureTraceName, TraceName>;\n```\n\n- A plain object literal with neither widens its values to `TraceName`.\n- `satisfies` alone already keeps each value's member type when the checked type is a union of literals, as an enum is. What `as const` adds is `readonly`, plus literal types for nested arrays and objects. It also marks the table as immutable, which is the condition under which the extensible-type exception above does not apply.\n\n## Type a built key by how it is built, and build it `as const`\n\n```typescript\n\u002F\u002F ✅ The map accepts only keys of this shape, so a key built from the wrong name does not compile.\nconst pending = new Map\u003C`${FeatureTraceName}:${string}`, PendingSpan>();\n\nconst key = `${params.name}:${params.id}` as const;\npending.get(key);\n```\n\n- A template literal expression infers as `string` unless it is marked `as const` or contextually typed. So narrowing a collection's key type fails with TS2345 at each `get`, `set` and `delete` that passes an unmarked key. Change the key type and every expression that builds a key together.\n- Measured with TypeScript 5.6.3 on [metamask-extension#46123 (preload Perps markets on unlock)](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fmetamask-extension\u002Fpull\u002F46123) at [`0118bcc256`](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fmetamask-extension\u002Fblob\u002F0118bcc25610de7238243c47d8ba37924251e017\u002Fapp\u002Fscripts\u002Fcontrollers\u002Fperps\u002Finfrastructure.ts#L274-L306). Narrowing only the span map's key type produced five TS2345 errors, and adding `as const` to its two key expressions cleared them.\n\n## Widen on purpose only where inference is unsound, and only at a boundary\n\nWhen a library's types claim more than its runtime guarantees, the correct annotation is wider. luxon types `plus(duration)` as returning `this`, so a valid `DateTime\u003Ctrue>` stays `DateTime\u003Ctrue>` after `plus()`, although the result is invalid past year 275760. Declaring the return as `DateTimeMaybeValid` restores the distinction the library erased.\n\nThat widening works only where the compiler has to use it:\n\n| form | forces the check? |\n|---|---|\n| `const x: DateTimeMaybeValid = start.plus(d)` | no, because control-flow analysis re-narrows `x` to its initializer |\n| `start.plus(d) satisfies DateTimeMaybeValid` | no, because it checks assignability and keeps the inferred type |\n| `start.plus(d) as DateTimeMaybeValid` | yes |\n| a parameter or return typed `DateTimeMaybeValid` | yes |\n\nSo the test is whether an annotation adds information inference lacks. Narrowing usually does. Widening does only where inference is wrong about the runtime.\n\n## Workflow\n\n1. Before writing `:`, hover or `tsc --noEmit` to see the inferred type, and write the annotation only if it is narrower, or a boundary widening of an unsound type.\n2. For a table that code never adds to, use `as const satisfies \u003CConstraint>`. For one that grows, annotate with `:`.\n3. For a collection keyed by built strings, type the key as the template literal it is, and add `as const` to every expression that builds one. Typecheck before proposing the change, since the key type and the builders have to change together.\n4. In review, run the proposed suggestion through `tsc` before posting it. A narrowing that leaves the builders unmarked fails the build.\n\n## Related\n\n- `derive-types` — take a type from its authoritative source instead of restating it.\n- `avoid-any` — the annotation that disables checking.\n- `tsc-blindspots` — divergence shapes the compiler cannot report, including a widened local.\n","# Avoid Widening\n\nDeepens `MetaMask\u002Fcontributor-docs` [`docs\u002Ftypescript.md`](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L40-L42), *Avoid unintentionally widening an inferred type with a type annotation*: \"Enforcing a wider type defeats the purpose of adding an explicit type declaration, as it _loses_ type information instead of adding it.\" `derive-types` covers where a type should come from. This skill covers how wide it should be, and `avoid-any` covers the annotation that turns checking off.\n\n## When To Use\n\n- Writing or reviewing a type annotation, a `satisfies` clause or an `as const`.\n- A lookup table maps one set of names to another, such as trace names or action types.\n- A collection is keyed by strings built from known parts, such as `` `${name}:${id}` ``.\n- Proposing a type change in review, where a widening suggestion reads as a tightening.\n\n## Annotate to add information, never to repeat or lose it\n\nCompare the annotation with the type inference already produces. Equal adds nothing, and wider loses information. Only a narrower annotation, or a deliberate widening at a boundary (below), is worth writing.\n\n| declaration | resulting type |\n|---|---|\n| `const name = 'foo'` | `\"foo\"` |\n| `const name: string = 'foo'` | `string`, widened |\n| `const ids = [1, 2] as const` | `readonly [1, 2]` |\n| `const ids: number[] = [1, 2]` | `number[]`, widened |\n\nTo check a value against a type without widening it, use `satisfies` ([`docs\u002Ftypescript.md` L134-L136](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L134-L136)). The exception is a mutable object, array or class that code adds to later. There the narrowest type excludes the additions, so annotate with `:` unless the value is meant to be immutable ([L201-L205](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fcontributor-docs\u002Fblob\u002F0c297e8a01be7482cc3ff0d047e5e51069adc442\u002Fdocs\u002Ftypescript.md#L201-L205)).\n\n## Keep immutable lookup tables literal\n\n```typescript\n\u002F\u002F ? The annotation widens every value to `TraceName`, so `NAMES[name]` no longer says which member it is.\nconst NAMES: Record\u003CFeatureTraceName, TraceName> = {\n  'Feature Open': TraceName.FeatureOpen,\n  'Feature Close': TraceName.FeatureClose,\n};\n\n\u002F\u002F ✅ Checks every key and value, keeps each value's member type, and makes the table read-only.\nconst NAMES = {\n  'Feature Open': TraceName.FeatureOpen,\n  'Feature Close': TraceName.FeatureClose,\n} as const satisfies Record\u003CFeatureTraceName, TraceName>;\n```\n\n- A plain object literal with neither widens its values to `TraceName`.\n- `satisfies` alone already keeps each value's member type when the checked type is a union of literals, as an enum is. What `as const` adds is `readonly`, plus literal types for nested arrays and objects. It also marks the table as immutable, which is the condition under which the extensible-type exception above does not apply.\n\n## Type a built key by how it is built, and build it `as const`\n\n```typescript\n\u002F\u002F ✅ The map accepts only keys of this shape, so a key built from the wrong name does not compile.\nconst pending = new Map\u003C`${FeatureTraceName}:${string}`, PendingSpan>();\n\nconst key = `${params.name}:${params.id}` as const;\npending.get(key);\n```\n\n- A template literal expression infers as `string` unless it is marked `as const` or contextually typed. So narrowing a collection's key type fails with TS2345 at each `get`, `set` and `delete` that passes an unmarked key. Change the key type and every expression that builds a key together.\n- Measured with TypeScript 5.6.3 on [metamask-extension#46123 (preload Perps markets on unlock)](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fmetamask-extension\u002Fpull\u002F46123) at [`0118bcc256`](https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fmetamask-extension\u002Fblob\u002F0118bcc25610de7238243c47d8ba37924251e017\u002Fapp\u002Fscripts\u002Fcontrollers\u002Fperps\u002Finfrastructure.ts#L274-L306). Narrowing only the span map's key type produced five TS2345 errors, and adding `as const` to its two key expressions cleared them.\n\n## Widen on purpose only where inference is unsound, and only at a boundary\n\nWhen a library's types claim more than its runtime guarantees, the correct annotation is wider. luxon types `plus(duration)` as returning `this`, so a valid `DateTime\u003Ctrue>` stays `DateTime\u003Ctrue>` after `plus()`, although the result is invalid past year 275760. Declaring the return as `DateTimeMaybeValid` restores the distinction the library erased.\n\nThat widening works only where the compiler has to use it:\n\n| form | forces the check? |\n|---|---|\n| `const x: DateTimeMaybeValid = start.plus(d)` | no, because control-flow analysis re-narrows `x` to its initializer |\n| `start.plus(d) satisfies DateTimeMaybeValid` | no, because it checks assignability and keeps the inferred type |\n| `start.plus(d) as DateTimeMaybeValid` | yes |\n| a parameter or return typed `DateTimeMaybeValid` | yes |\n\nSo the test is whether an annotation adds information inference lacks. Narrowing usually does. Widening does only where inference is wrong about the runtime.\n\n## Workflow\n\n1. Before writing `:`, hover or `tsc --noEmit` to see the inferred type, and write the annotation only if it is narrower, or a boundary widening of an unsound type.\n2. For a table that code never adds to, use `as const satisfies \u003CConstraint>`. For one that grows, annotate with `:`.\n3. For a collection keyed by built strings, type the key as the template literal it is, and add `as const` to every expression that builds one. Typecheck before proposing the change, since the key type and the builders have to change together.\n4. In review, run the proposed suggestion through `tsc` before posting it. A narrowing that leaves the builders unmarked fails the build.\n\n## Related\n\n- `derive-types` — take a type from its authoritative source instead of restating it.\n- `avoid-any` — the annotation that disables checking.\n- `tsc-blindspots` — divergence shapes the compiler cannot report, including a widened local.\n",{"name":5,"maturity":44,"description":7},"experimental","main","a0ec29ada8d53edf5a3f24370bec058767157433","domains\u002Ftypescript\u002Fskills\u002Favoid-widening",11,"https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills","https:\u002F\u002Fgithub.com\u002FMetaMask","https:\u002F\u002Fmetamask.io","MetaMask brings Ethereum to your web browser","2026-11-14 02:01:03",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add MetaMask\u002Fskills --skill avoid-widening",{"tool":60,"command":61},"bunx","bunx skills add MetaMask\u002Fskills --skill avoid-widening",{"tool":63,"command":64},"pnpm","pnpm dlx skills add MetaMask\u002Fskills --skill avoid-widening","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Ftypescript\u002Fskills\u002Favoid-widening\u002Fskill.md",true,[68],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"agents\u002Fopenai.yaml","REFERENCE","参考文档",543,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FColin4k1024\u002Ftsp\u002Fskills\u002Froles\u002Ftech-lead\u002Fagents\u002Fopenai.yaml",[75,83,91,118,136,143],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":82},"01M7B6HMM9ND19MSEXPDW7Q3F8","recipe-plan-and-dispatch","Plan a ticket with the engineer before a recipe fix-bug or dev run. Agree the acceptance criteria and an implementation plan, write it as an approved plan file, and print the prompt that starts the run with any agent and model. Never edits product code or starts the run.","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fagentic\u002Fskills\u002Frecipe-plan-and-dispatch\u002Fskill.md",[],[],"2026-11-15 14:19:17",{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":90},"01M72GPQFVTGCPVK22DSDJXEJY","recipe-library-audit","Run every recipe of a team recipe library on one client with mm-harness, classify each result with the failing node and exact error, and review naming and composability. Produces a per-client table; changes nothing.","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fagentic\u002Fskills\u002Frecipe-library-audit\u002Fskill.md",[],[],"2026-11-10 22:39:42",{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":39},"01M70PKJH3WSTFMSA8VYQWNDW9","recipe-performance","Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold\u002Fwarm\u002Fbackground-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout\u002Fpaint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fagentic\u002Fskills\u002Frecipe-performance\u002Fskill.md",[],[98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117],"recipe","recipe performance","performance","analysis","app","cold","critical","tasks","react","browser","layout","screen","network","metamask","flow","recipes","deterministic","harness","mm","sentry",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":39},"01M6CGJ7AEJCZSRGF3PBE6EWBG","x402-payments","Build x402 payment flows using MetaMask Smart Accounts Kit, machine to machine payments over HTTP with ERC-7710 delegations and ERC-7715 Advanced Permissions","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fweb3-tools\u002Fskills\u002Fx402-payments\u002Fskill.md",[],[125,126,127,23,128,129,130,131,111,132,33,133,134,135],"x402","x402 payments","payments","payment","advanced","flows","machine","kit","permissions","smart accounts kit","http",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":39},"01M6CGJ4AEKJZJWJ704SZTWQ5T","smart-accounts-kit","Build dApps with MetaMask Smart Accounts Kit — ERC-4337 smart accounts, delegations, and Advanced Permissions (ERC-7715)","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fweb3-tools\u002Fskills\u002Fsmart-accounts-kit\u002Fskill.md",[],[132,134,133,33,23,129,111],{"skillNo":144,"name":145,"nameZh":6,"description":146,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":147,"categories":148,"keywords":149,"publishedAt":39},"01M6CGJ11KGB6862Z1ADYTMKYZ","oh-my-opencode","Multi-agent orchestration plugin for OpenCode. Use when the user wants to install, configure, or operate oh-my-opencode — including agent delegation, ultrawork mode, Prometheus planning, background tasks, category-based task routing, model resolution, tmux integration, or any oh-my-opencode feature. Covers installation, configuration, all agents (Sisyphus, Oracle, Librarian, Explore, Atlas, Prometheus, Metis, Momus), all categories, slash commands, hooks, skills, MCPs, and troubleshooting.","https:\u002F\u002Fgithub.com\u002FMetaMask\u002Fskills\u002Fblob\u002Fmain\u002Fdomains\u002Fweb3-tools\u002Fskills\u002Foh-my-opencode\u002Fskill.md",[],[150,151,152,153,154,155,156,157,105,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175],"oh my opencode","my","opencode","hooks","explore","model","momus","code","ultrawork","install","multi-agent","tmux","prometheus","planning","use","orchestration","categories","operate","mode","metis","configure","when","oracle","agent orchestration","librarian","delegation"]