---
name: typescript
description: TypeScript 7 types and tsconfig.
title: typescript
canonical_url: https://skilld.dev/gh/pymodel/react-frontend-skills/typescript
last_updated: 2026-11-12T09:04:44.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> 44 supporting files sit beside this SKILL.md. When the Skill refers to one, fetch https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/PATH with PATH replaced.
>
> If the user asked to install this Skill, run `npx skilld install pymodel/react-frontend-skills/typescript`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/typescript`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/pymodel/react-frontend-skills/typescript) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/typescript`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/typescript --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/typescript --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# TypeScript Best Practices

Comprehensive TypeScript 7 guide with 44 rules across 8 categories, covering compiler configuration, type-system performance, async code, modules, safety, and measured runtime optimization.

## When to Apply

Reference these guidelines when:
- Configuring tsconfig.json for a new or existing project
- Writing complex type definitions or generics
- Optimizing async/await patterns and data fetching
- Organizing modules and managing imports
- Reviewing code for compilation or runtime performance

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Type System Performance | CRITICAL | `type-` |
| 2 | Compiler Configuration | CRITICAL | `tscfg-` |
| 3 | Async Patterns | HIGH | `async-` |
| 4 | Module Organization | HIGH | `module-` |
| 5 | Type Safety Patterns | MEDIUM-HIGH | `safety-` |
| 6 | Memory Management | MEDIUM | `mem-` |
| 7 | Runtime Optimization | LOW-MEDIUM | `runtime-` |
| 8 | Advanced Patterns | LOW | `advanced-` |

## Table of Contents

1. Type System Performance — **CRITICAL**
   - 1.1 [Add Explicit Return Types to Exported Functions](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-explicit-return-types.md) — CRITICAL (faster declaration emit)
   - 1.2 [Avoid Deeply Nested Generic Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-avoid-deep-generics.md) — CRITICAL (prevents exponential instantiation cost)
   - 1.3 [Avoid Large Union Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-avoid-large-unions.md) — CRITICAL (quadratic O(n²) comparison cost)
   - 1.4 [Extract Conditional Types to Named Aliases](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-extract-conditional-types.md) — CRITICAL (enables compiler caching, prevents re-evaluation)
   - 1.5 [Limit Type Recursion Depth](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-limit-recursion-depth.md) — CRITICAL (prevents exponential type expansion)
   - 1.6 [Prefer Interfaces Over Type Intersections](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-interfaces-over-intersections.md) — CRITICAL (faster type resolution)
   - 1.7 [Simplify Complex Mapped Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/type-simplify-mapped-types.md) — CRITICAL (reduces type computation)
2. Compiler Configuration — **CRITICAL**
   - 2.1 [Configure Include and Exclude Properly](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-exclude-properly.md) — CRITICAL (prevents scanning thousands of unnecessary files)
   - 2.2 [Enable Incremental Compilation](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-enable-incremental.md) — CRITICAL (faster rebuilds)
   - 2.3 [Choose skipLibCheck Deliberately](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-skip-lib-check.md) — CRITICAL (faster compilation)
   - 2.4 [Enable strictFunctionTypes for Sound Function Assignments](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-strict-function-types.md) — CRITICAL (enables optimized variance checking)
   - 2.5 [Use isolatedModules for Single-File Transpilers](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-isolate-modules.md) — CRITICAL (faster transpilation with bundlers)
   - 2.6 [Use Project References for Large Codebases](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-project-references.md) — CRITICAL (faster incremental builds)
   - 2.7 [Configure tsconfig for TypeScript 7](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/tscfg-typescript-7.md) — CRITICAL
3. Async Patterns — **HIGH**
   - 3.1 [Annotate Async Function Return Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/async-explicit-return-types.md) — HIGH (prevents runtime errors, improves inference)
   - 3.2 [Avoid await Inside Loops](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/async-avoid-loop-await.md) — HIGH (scales linearly with the number of iterations)
   - 3.3 [Avoid Unnecessary async/await](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/async-avoid-unnecessary-async.md) — HIGH (eliminates microtask queue overhead)
   - 3.4 [Defer await Until Value Is Needed](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/async-defer-await.md) — HIGH (enables implicit parallelization)
   - 3.5 [Use Promise.all for Independent Operations](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/async-parallel-promises.md) — HIGH (improvement in I/O-bound code)
4. Module Organization — **HIGH**
   - 4.1 [Avoid Barrel File Imports](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/module-avoid-barrel-imports.md) — HIGH (import cost, larger bundles)
   - 4.2 [Avoid Circular Dependencies](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/module-avoid-circular-dependencies.md) — HIGH (prevents runtime undefined errors and slow compilation)
   - 4.3 [Control @types Package Inclusion](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/module-control-types-inclusion.md) — HIGH (prevents type conflicts and reduces memory usage)
   - 4.4 [Use Dynamic Imports for Large Modules](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/module-dynamic-imports.md) — HIGH (reduces initial bundle)
   - 4.5 [Use Type-Only Imports for Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/module-use-type-imports.md) — HIGH (eliminates runtime imports for type information)
5. Type Safety Patterns — **MEDIUM-HIGH**
   - 5.1 [Enable strictNullChecks](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-strict-null-checks.md) — MEDIUM-HIGH
   - 5.2 [Prefer unknown Over any](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-prefer-unknown-over-any.md) — MEDIUM-HIGH
   - 5.3 [Use Assertion Functions for Validation](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-assertion-functions.md) — MEDIUM-HIGH
   - 5.4 [Use const Assertions for Literal Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-const-assertions.md) — MEDIUM-HIGH
   - 5.5 [Use Exhaustive Checks for Union Types](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-exhaustive-checks.md) — MEDIUM-HIGH
   - 5.6 [Use Type Guards for Runtime Type Checking](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/safety-use-type-guards.md) — MEDIUM-HIGH
6. Memory Management — **MEDIUM**
   - 6.1 [Avoid Closure Memory Leaks](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/mem-avoid-closure-leaks.md) — MEDIUM (prevents retained references in long-lived callbacks)
   - 6.2 [Avoid Global State Accumulation](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/mem-avoid-global-state.md) — MEDIUM (prevents unbounded memory growth)
   - 6.3 [Clean Up Event Listeners](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/mem-cleanup-event-listeners.md) — MEDIUM (prevents unbounded memory growth)
   - 6.4 [Clear Timers and Intervals](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/mem-clear-timers.md) — MEDIUM (prevents callback retention and repeated execution)
   - 6.5 [Use WeakMap for Object Metadata](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/mem-use-weakmap-for-metadata.md) — MEDIUM (prevents memory leaks, enables automatic cleanup)
7. Runtime Optimization — **LOW-MEDIUM**
   - 7.1 [Avoid Object Spread in Hot Loops](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-avoid-object-spread-in-loops.md) — LOW-MEDIUM
   - 7.2 [Hoist Loop-Invariant Work in Measured Hot Paths](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-cache-property-access.md) — LOW-MEDIUM
   - 7.3 [Prefer Native Array Methods Over Lodash](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-prefer-array-methods.md) — LOW-MEDIUM
   - 7.4 [Use for-of for Simple Iteration](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-use-for-of-for-iteration.md) — LOW-MEDIUM
   - 7.5 [Use Modern String Methods](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-use-string-methods.md) — LOW-MEDIUM
   - 7.6 [Use Set/Map for O(1) Lookups](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/runtime-use-set-for-lookups.md) — LOW-MEDIUM
8. Advanced Patterns — **LOW**
   - 8.1 [Use Branded Types for Type-Safe IDs](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/advanced-branded-types.md) — LOW (prevents mixing incompatible ID types)
   - 8.2 [Use satisfies for Type Validation with Inference](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/advanced-satisfies-operator.md) — LOW (prevents property access errors, enables reliable autocomplete)
   - 8.3 [Use Template Literal Types for String Patterns](https://skilld.dev/api/skills-raw/pymodel/react-frontend-skills/typescript/references/advanced-template-literal-types.md) — LOW (prevents string format errors at compile time)

## How to Use

Run in the project root first:

```bash
npx -y @pymodel/react-frontend-skills detect   # installed vs. targeted versions
```

Read `references/<rule-id>.md` for each rule above that matches the task: why it matters, then incorrect vs. correct code.

## References

1. [https://github.com/microsoft/TypeScript/wiki/Performance](https://github.com/microsoft/TypeScript/wiki/Performance)
2. [https://www.typescriptlang.org/docs/handbook/](https://www.typescriptlang.org/docs/handbook/)
3. [https://v8.dev/blog](https://v8.dev/blog)
4. [https://nodejs.org/en/learn/diagnostics/memory](https://nodejs.org/en/learn/diagnostics/memory)
