agentsclimarketplace

Typescript coding

Skill nguyenthdat/opencode-manager/.opencode/skills/typescript-coding

Comprehensive idiomatic TypeScript/JavaScript guidance: 171 prioritized rules across 14 categories. Use when writing, reviewing, refactoring, optimizing, or debugging TypeScript or JavaScript (`.ts`, `.tsx`, `.js`, `.jsx`, `tsconfig.json`, `package.json`). Preserve the target project's declared TypeScript version, module system, and strictness settings; apply `satisfies`, `verbatimModuleSyntax`, `noUncheckedIndexedAccess`, and other modern-config guidance only when the project's toolchain supports them.From its SKILL.md

Install
npx -y skills add nguyenthdat/opencode-manager --skill typescript-coding

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 20 days oldThe repository was created 20 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

30.2 KB, ~7.5k tokens by cl100k_base, as published. Nobody here has run it

TypeScript Best Practices

Comprehensive guide for writing high-quality, idiomatic TypeScript and modern JavaScript-via-TypeScript code. Contains 171 rules across 14 categories, prioritized by impact. Project constraints override generic defaults: preserve the declared TypeScript version, tsconfig.json strictness settings, module system (ESM/CJS), and target runtime unless the user explicitly requests a migration.

When to Apply

Reference these guidelines when:

  • Writing new TypeScript/JavaScript functions, classes, or modules
  • Implementing error handling or async/await code
  • Designing public APIs for libraries or shared packages
  • Reviewing code for type-safety gaps (any, unchecked assertions, missing narrowing)
  • Optimizing bundle size, allocations, or hot paths
  • Structuring a project, monorepo, or module boundaries
  • Writing or reviewing tests (Vitest/Jest)
  • Migrating a codebase to stricter tsconfig.json settings or newer TypeScript releases

Modern TypeScript & tsconfig Notes

TypeScript's release cadence (5.4–5.9+ as of 2025) is additive, not edition-based like Rust — there is no single "flip a switch" migration. Preserve a project's existing tsconfig.json and only apply the notes below when the installed TypeScript version and runtime actually support them; verify with npx tsc -v and the project's package.json engines field before assuming a feature is available.

  • strict: true. The single highest-leverage setting. It bundles strictNullChecks, noImplicitAny, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, and alwaysStrict. New projects should start here; existing projects should ratchet toward it incrementally (strictNullChecks first).
  • satisfies operator (5.0+). Validates that a literal conforms to a type without widening the literal's inferred type the way an : Type annotation would — see type-satisfies-operator.
  • verbatimModuleSyntax (5.0+). Replaces the older isolatedModules + importsNotUsedAsValues combination; makes type-only imports/exports explicit (import type) so single-file transpilers (esbuild, swc, Babel) never accidentally elide or keep a runtime import incorrectly.
  • moduleResolution: "bundler" (5.0+). Matches how modern bundlers (Vite, esbuild, webpack) actually resolve packages, including exports map conditions, without requiring file extensions on relative imports the way "node16"/"nodenext" does.
  • noUncheckedIndexedAccess. Makes T[K] on an index signature or array return T | undefined instead of T, closing a large hole in strict mode around out-of-bounds/missing-key access.
  • Const type parameters (const T extends ..., 5.0+). Infers generic arguments as their literal (as const-like) form without callers having to write as const themselves at every call site.
  • Template literal types & as const. Together they let you derive precise string-literal unions from data instead of hand-maintaining parallel enum/union declarations — see type-template-literal and type-const-assertion.
  • ESM vs. CJS interop. Node.js, bundlers, and TypeScript increasingly default to ESM. Use "type": "module" in package.json for new packages, import/export syntax, and the exports field to declare public entry points; reserve "type": "commonjs" and .cjs for legacy consumers. Mixed dual-package builds should generate both outputs rather than relying on runtime shims.
  • isolatedModules. Required by every non-tsc transpiler (esbuild, swc, Babel) because they compile files independently without full type information; keep it on for any project using such a toolchain.

Rule Categories by Priority

PriorityCategoryImpactPrefixRules
1Type Safety & NarrowingCRITICALtype-16
2Error HandlingCRITICALerr-13
3Async/Promises/ConcurrencyCRITICALasync-16
4API/Module DesignHIGHapi-14
5Immutability & Data PatternsHIGHimm-10
6Functional PatternsHIGHfn-10
7Naming ConventionsMEDIUMname-12
8TestingMEDIUMtest-13
9DocumentationMEDIUMdoc-9
10Performance PatternsMEDIUMperf-12
11Node.js/RuntimeMEDIUMnode-9
12Project Structure & ToolingLOWproj-11
13LintingLOWlint-10
14Anti-patternsREFERENCEanti-16

Quick Reference

1. Type Safety & Narrowing (CRITICAL)

2. Error Handling (CRITICAL)

3. Async/Promises/Concurrency (CRITICAL)

4. API/Module Design (HIGH)

5. Immutability & Data Patterns (HIGH)

6. Functional Patterns (HIGH)

7. Naming Conventions (MEDIUM)

8. Testing (MEDIUM)

9. Documentation (MEDIUM)

10. Performance Patterns (MEDIUM)

11. Node.js/Runtime (MEDIUM)

12. Project Structure & Tooling (LOW)

13. Linting (LOW)

14. Anti-patterns (REFERENCE)


Recommended tsconfig.json / package.json Settings

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",       // or "nodenext" for a Node.js-only library
    "lib": ["ES2022"],
    "strict": true,                       // strictNullChecks, noImplicitAny, etc.
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "dist",
    "rootDir": "src"
  },
  "include": ["src"],
  "exclude": ["dist", "node_modules"]
}
// package.json (relevant fields for an ESM-first published package)
{
  "type": "module",
  "engines": { "node": ">=20" },
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.js"
    }
  },
  "files": ["dist"],
  "sideEffects": false,
  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "typecheck": "tsc --noEmit",
    "lint": "eslint . --max-warnings 0",
    "test": "vitest run"
  }
}

How to Use

This skill provides rule identifiers for quick reference. When generating or reviewing TypeScript/JavaScript code:

  1. Check relevant category based on task type
  2. Apply rules with matching prefix
  3. Prioritize CRITICAL > HIGH > MEDIUM > LOW
  4. Read rule files in rules/ for detailed examples

Rule Application by Task

TaskPrimary Categories
New function/moduletype-, err-, name-
New public API/packageapi-, type-, doc-
Async/network codeasync-, err-
Error handlingerr-, type-
State managementimm-, fn-
Performance tuningperf-, async-, node-
Writing teststest-
Project/monorepo setupproj-, lint-, node-
Code reviewanti-, lint-

Related Skills

  • design-patterns - choosing and implementing GoF and idiomatic patterns; apply alongside this skill's API and naming rules for pattern-heavy TypeScript design.
  • security-review - security-focused audit checklists; apply alongside this skill's error-handling and async rules when reviewing TypeScript code for vulnerabilities.

Sources

This skill synthesizes best practices from:

What ships with it: 171 files

464.4 KB alongside SKILL.md

131 more files not listed here. See all 171 in the repository.

Keep looking

Skills are one crate of 326,645. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.