typescript-advanced
Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects. Don't use for plain JavaScript, runtime validation libraries (Zod, Yup), or basic TypeScript syntax questions.
What this skill does
# TypeScript Advanced Types
Comprehensive guidance for mastering TypeScript's advanced type system. This SKILL.md is a **dispatcher** — the detailed code patterns live in `references/*.md` and are loaded on demand.
## Required Reading Router
Read the matching reference before producing code. Each is one level deep and self-contained.
| Goal | Read |
|------|------|
| Refresh foundational generics, conditional types, mapped types, template literals, utility types | `references/core-concepts.md` |
| Build a type-safe event emitter, API client, builder, deep utility, form validator, or discriminated state machine | `references/advanced-patterns.md` |
| Use `infer`, type guards, assertion functions, or write compile-time type tests | `references/type-inference.md` |
| Apply project-level configuration, interfaces-vs-types, error handling, performance | `references/best-practices.md` |
## When to Use This Skill
- Building type-safe libraries or frameworks
- Creating reusable generic components
- Implementing complex type inference logic
- Designing type-safe API clients
- Building form validation systems
- Creating strongly-typed configuration objects
- Implementing type-safe state management
- Migrating JavaScript codebases to TypeScript
## Decision Map
Use these decision points to pick the right tool before writing code:
| Scenario | Recommendation |
|----------|----------------|
| Function parameters | Always explicit |
| Return types | Let TypeScript infer (usually) |
| Local variables | Let TypeScript infer |
| Public API boundaries | Always explicit |
| Object shapes (extensible) | Use `interface` |
| Union types | Use `type` |
| Computed/mapped types | Use `type` |
| Runtime-narrowing of `unknown` | Type guard or assertion (see `references/type-inference.md`) |
| Variant data with shared field | Discriminated union (see `references/advanced-patterns.md` Pattern 6) |
## Core Guidelines
1. **Use `unknown` over `any`** — Enforce type checking at boundaries.
2. **Prefer `interface` for object shapes** — Better error messages, declaration merging.
3. **Use `type` for unions and computed types** — More flexible for mapped/conditional types.
4. **Leverage type inference** — Let TypeScript infer when possible; annotate only at boundaries.
5. **Create helper types** — Build reusable type utilities (see `references/advanced-patterns.md`).
6. **Use const assertions** — Preserve literal types.
7. **Avoid type assertions** — Prefer type guards (see `references/type-inference.md`).
8. **Document complex types** — Add JSDoc on exported public types.
9. **Use strict mode** — Enable all strict compiler options.
10. **Test your types** — Use `Expect<Equal<X, Y>>` compile-time tests (see `references/type-inference.md`).
## Recommended `tsconfig.json`
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"moduleResolution": "Bundler"
}
}
```
For deeper configuration rationale, read `references/best-practices.md`.
## Common Pitfalls
1. **Over-using `any`** — Defeats the purpose of TypeScript.
2. **Ignoring strict null checks** — Can lead to runtime errors.
3. **Too complex types** — Can slow down compilation.
4. **Not using discriminated unions** — Misses type narrowing opportunities.
5. **Forgetting `readonly` modifiers** — Allows unintended mutations.
6. **Circular type references** — Can cause compiler errors.
7. **Not handling edge cases** — Empty arrays, null values, missing keys.
## Performance Considerations
- Avoid deeply nested conditional types.
- Use simple types when possible.
- Cache complex type computations behind `type Alias = ...`.
- Limit recursion depth in recursive types (TS caps around 50).
- Use build tools to skip type checking in production.
- Prefer type guards over type assertions for runtime safety.
- Keep union types small in hot paths.
See `references/best-practices.md#performance-considerations` for deeper analysis.
## External Resources
- TypeScript Handbook — https://www.typescriptlang.org/docs/handbook/
- Type Challenges — https://github.com/type-challenges/type-challenges
- TypeScript Deep Dive — https://basarat.gitbook.io/typescript/
- Effective TypeScript — book by Dan Vanderkam
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.