AgentStack
SKILL verified MIT Self-run

Typescript Clean Code

skill-mblauberg-provenant-typescript-clean-code · by mblauberg

Use as a TypeScript or JavaScript correctness lens for type modelling, strictness, null/error boundaries, async ownership, and tests. Not a lifecycle owner or reason to rewrite stable conventions; combine with the task owner.

No reviews yet
0 installs
1 views
0.0% view→install

Install

$ agentstack add skill-mblauberg-provenant-typescript-clean-code

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Typescript Clean Code? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

TypeScript clean code

Generic clean-code sense is assumed. Apply these TypeScript-specific rules. See references/typescript-patterns.md for worked examples.

Types

  • Make illegal states unrepresentable. Prefer a discriminated union to

optional fields plus a flag.

  • Prefer unknown to any. Narrow unknown input. Isolate and explain any

required by untyped interop, compatibility work or deliberate escape hatches.

  • Do not launder types with assertions. Narrow with guards, in, typeof

or instanceof, or validate boundaries. Avoid as and as unknown as; as const and satisfies are fine.

  • Enforce exhaustiveness with never. Use default: assertNever(x) for

union switches.

  • Derive, do not duplicate. Use z.infer, keyof, typeof, mapped types,

Pick or Omit; keep one source for each shape.

  • Use type for unions/functions/mapped types and follow the repository's

established type/interface convention for object shapes.

  • Brand primitives that must not be interchanged, such as UserId and

OrderId.

tsconfig

  • Target strict, noUncheckedIndexedAccess (indexed access can be

undefined), exactOptionalPropertyTypes, noImplicitOverride, noFallthroughCasesInSwitch and useUnknownInCatchVariables. For an existing codebase, stage flags with an explicit migration and no silent public-type changes.

  • Run tsc --noEmit in CI.

Errors & null

  • catch binds unknown. Narrow before accessing it.
  • Wrap lower-layer errors in caller-meaningful classes with { cause: err }.
  • Prefer the repository/API convention for null versus undefined; do not

churn a stable boundary for taste alone. Return [] for empty collections and a Result/union for expected failure. Throw only for exceptional cases. Prefer ?. and ?? to scattered null checks.

  • Never widen a function's return to include null/undefined "just in case"; that pushes a guard onto every caller.

Async

  • Give every promise an owner and rejection path. Await it, return it, supervise

it in a task group/queue, or use void task().catch(report). A bare void only acknowledges a linter; it does not handle rejection. Enable no-floating-promises with project-appropriate options.

  • Parallelise only independent work within measured socket, memory, rate-limit,

cancellation and failure-aggregation bounds. Promise.all suits a small fixed set; use a bounded pool/queue for large collections and deliberate sequential awaits when ordering or backpressure matters.

  • Type async functions Promise; do not add async only for a caller.

Tests

  • Test type contracts with expectTypeOf and @ts-expect-error for cases that

must not compile.

  • Type mocks to real interfaces; any-typed mocks pass vacuously.
  • Use Arrange-Act-Assert, one public behaviour per test, and prefer

toEqual/toStrictEqual to manual field assertions.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.