/tsh-stack-nodejs:modelling-types-for-nodejsfrom TSH Stack: Node.js
Guides modelling types in Node.js/TypeScript backends so the compiler catches bugs: discriminated unions, branded ids, const-object unions, satisfies, unknown over any, and schema-derived types at boundaries. Use when shaping DTOs, entities, commands, or reviewing code for unsafe casts.
Ships in TSH Stack: Node.js. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
How to model types in a Node/TypeScript backend so wrong states fail to compile
rather than reaching production. The organising principle: a type is a claim, and
the compiler can only protect you from claims that are true. Every any, every
unchecked assertion, and every over-wide signature trades a compile-time guarantee
for a runtime hope.
This is the type-modelling layer. The tsconfig.json, version policy, and
decorator settings it assumes belong to
configuring-typescript-for-nodejs,
and the NestJS/TypeORM feature patterns to
implementing-nestjs-api. All three ship in
this plugin, so those links always resolve.
interface vs type, optional
fields vs a discriminated union, a branded id vs a bare string.any, unsafe assertions, non-null !, or types that
claim more than the code proves.Read the repository's own code and tsconfig.json before applying anything here.
Local conventions outrank these defaults — a codebase that uses enum
consistently stays consistent; apply this guidance where the repo is silent, and
record a deliberate deviation rather than silently mixing both.
Framework requirements also outrank this skill. NestJS, TypeORM, and the validation library in use constrain how DTOs and entities are shaped; where a framework skill and this one disagree, the framework skill wins for the files it owns.
| Severity | Rule |
|---|---|
| NEVER | Use any to silence an error. Use unknown at the boundary and narrow with a type guard or a schema parse; a surviving any carries a comment naming the reason and the condition for removal. |
| NEVER | Use a type assertion to overrule the compiler — as unknown as T, or a non-null ! on a value the code cannot prove is present — without a comment justifying the claim. as const is the exception; it narrows rather than widens. |
| MUST | Validate every value entering the process (HTTP body, query string, env, messages, third-party responses) and derive its static type from the schema (z.infer), never cast a response body to a hand-written interface. |
| PREFER | A discriminated union with a literal discriminant over an interface with mutually exclusive optional fields, and add an exhaustiveness check so a new variant fails to compile until every consumer handles it. |
| PREFER | Branded types for ids and validated values that cross module boundaries, constructed through one validating function so the brand means "checked". |
| PREFER | A const object plus a derived union over enum; NEVER a numeric enum for a persisted or serialized value, whose stored integers become an unversioned contract. |
| PREFER | satisfies over an annotation when you want validation and the narrow inferred type (config objects, lookup tables). |
| NEVER | Add a type parameter that appears only in the return position to hand back an unproven value — parse<T>(raw): T is an unchecked assertion in generic syntax; have the caller narrow an unknown instead. A factory that returns a container of a caller-chosen type (createSet<T>(): Set<T>) is the opposite and is fine — it asserts nothing. |
| MUST | Comment every suppression and prefer @ts-expect-error over @ts-ignore; never a file-level @ts-nocheck in application code. A growing suppression count means a type is modelled wrongly. |
| Reference | Load when | Covers |
|---|---|---|
| Type modelling patterns | Applying any rule above to real code, or you need the worked example and the full rationale | Each pattern with backend code: unknown over any, assertions, making illegal states unrepresentable, branded types, unions over enums, interface vs type, generic discipline, satisfies, boundaries, suppression |
enum/union, interface/type, and validation library
it already uses — before proposing a shape.unknown until a
schema parses it; anything crossing a module boundary as a bare primitive id is a
swap waiting to happen.What SKILL.md sets; muted values are Claude Code's defaults
Trigger on: deciding how to shape a type (union vs enum, interface vs type, optional fields vs a discriminated union), a review comment about `any`, `as`, non-null `!`, or an unchecked cast, branding ids that must not be swapped, typing an HTTP body/env/message boundary, choosing `satisfies` vs an annotation, or a generic that only appears in a return position. For *compiler configuration* — tsconfig, versions, decorators — use configuring-typescript-for-nodejs instead.
Three short reads, in order
3 skills in this plugin
/configuring-typescript-for-nodejsConfigures TypeScript for Node.js server projects: which version to pin, the tsconfig baseline for a Node-resolved runtime, and the decorator-metadata settings NestJS and TypeORM require. Use when starting a Node service, editing a server tsconfig, diagnosing emitDecoratorMetadata or class-field problems, or upgrading TypeScript in a backend./implementing-nestjs-apiGuides implementation and review of NestJS 11 REST APIs with TypeScript, @nestjs/cqrs, TypeORM 0.3, and @nestjs/platform-express. Use when bootstrapping a service, organizing vertical feature slices, adding CQRS behavior, implementing a REST API change, or reviewing a NestJS change — a command or query handler, module, TypeORM repository, or DTO — for framework, CQRS, persistence and testability risks.npx claudepluginhub thesoftwarehouse/agentic-collections --plugin tsh-stack-nodejsOther plugins' skills for the same job