use-modern-javascript-typescript

📁 lednhatkhanh/skills 📅 Today
0
总安装量
1
周安装量
安装命令
npx skills add https://github.com/lednhatkhanh/skills --skill use-modern-javascript-typescript

Agent 安装分布

amp 1
cline 1
opencode 1
cursor 1
kimi-cli 1
codex 1

Skill 文档

Use Modern JavaScript + TypeScript

Apply this skill to produce predictable, type-safe, and maintainable JS/TS code with function-first design and strict defaults.

Quick Start

  1. Confirm runtime, module system, and TypeScript version before coding.
  2. Enable strictness (strict + alwaysStrict) and enforce erasable TS syntax.
  3. Prefer function declarations for named logic and composition over classes.
  4. Prefer type over interface unless interface-specific behavior is required.
  5. Use modern operators (?., ??) and immutable patterns by default.
  6. Load only the reference files needed for the task.

Reference Routing

Workflow

  1. Scope the change.
  • Identify runtime assumptions (node, browser, bundler, ESM/CJS) and compatibility constraints.
  • Identify API surface and behavior contracts before editing internals.
  1. Set language guardrails.
  • Enforce strict mode semantics.
  • Enforce erasable TS syntax only.
  • Enforce function-first design and type consistency.
  1. Implement for correctness first.
  • Write explicit nullability handling.
  • Keep data immutable unless mutation is required and localized.
  • Prefer exhaustive control flow for tagged unions and status states.
  1. Optimize after correctness.
  • Defer expensive work until needed.
  • Choose lazy or concurrent execution only when semantics remain correct.
  • Measure before and after when touching hot paths.
  1. Validate quality gates.
# project-specific command names vary; run equivalents for:
pnpm -s tsc --noEmit
pnpm -s lint
pnpm -s test

Run additional checks when relevant:

pnpm -s test -- --runInBand          # deterministic async debugging
pnpm -s test -- --coverage           # branch/edge-case confidence
pnpm -s vitest bench                 # benchmark hot paths (or equivalent)

Non-Negotiable Rules

  • Use function declarations for named functions; avoid function expressions for named logic.
  • Prefer functions and composition over classes.
  • Prefer type over interface when either works.
  • Keep TypeScript erasable-only; avoid TS-only runtime emit constructs.
  • Use unknown instead of any unless unavoidable and justified.
  • Use ?. and ?? over fragile chained guards and || defaults.
  • Avoid mutating shared arrays/objects; prefer non-mutating alternatives.
  • Do not use forEach for async control flow.
  • Do not silently swallow errors or rejected promises.

Output Expectations

When applying this skill in a coding task:

  1. State the runtime + module assumptions.
  2. Call out strictness and erasable-syntax decisions.
  3. Highlight correctness decisions around nullability, async flow, and mutation.
  4. Mention performance decisions only when evidence or profiling supports them.
  5. List what was validated (typecheck, lint, test, and any perf checks).