Top down typescript

From paleo/alignfirst · View interactive version

Top down typescript is an AI agent skill from the GitHub repository paleo/alignfirst. TypeScript and JavaScript coding style conventions, centered on top-down narrative ordering (caller first, helpers below) and functions over classes. Read before writing or reviewing TypeScript/JavaScript code, including code inside a spec or a plan.

How to use this skill

Skill file

Top-Down TypeScript Coding Style

General Rules

Code Organization

Usage comes first, implementation after. Exception: with inheritance — when an interface _extends_ another, write the parent first.

```ts

// 1. Imports

import { ... } from "...";

// 2. Module-level constants and variables (exported first, then internal)

export const PUBLIC_CONST = ...;

const INTERNAL_CONST = ...;

// 3. Shared types — main type first, then types it references

export interface MainType {

detail: DetailType;

}

export interface DetailType { ... }

// 4. Entry-point (exported) function

export function doThing() {

stepOne();

stepTwo();

}

// 5. Internal functions called by the entry point, in call order

function stepOne() {

stepOneHelper();

}

function stepOneHelper() { ... }

function stepTwo() { ... }

```

Code Quality Standards

Imports

TypeScript, JavaScript

OOP

Adding a package dependency

Before adding a dependency or dev-dependency, search the codebase first and reuse the version already in use. If not found, install the latest version using the default install command.

Commit, PR/MR, and changeset messages

Never add AI attribution — Co-Authored-By: …, "Generated with …", or similar — to a commit, PR, MR, or changeset message.

Changeset messages

Write for someone already using the project who wants to know what changed, in a few words. Mention only what is actionable for them; skip the _why_ and the internal details. Always a single short paragraph.

When a version mixes actionable and non-actionable changes (for example a big refactoring plus a small feature), mention only the actionable one. Mention non-actionable changes only when there is nothing else for the user.

Version bumps

Never bump a package from 0.x.x to 1.0.0 unless explicitly instructed. Breaking changes are accepted while the major version is 0.

Improving code quality

SRP - Single Responsibility Principle

Think of it as narrative decomposition: the caller reads like a paragraph that names what happens; each helper expands one sentence of that paragraph.

For example, this code:

export function myFunction() {
  // Check something
  // ... 20 lines ...

  // Do something
  // ... 20 lines ...
}

… should be refactored in:

export function myFunction() {
  checkSomething();
  doSomething();
}

function checkSomething() {
  // ... 20 lines ...
}

function doSomething() {
  // ... 20 lines ...
}

Guidelines:

DRY - Don't Repeat Yourself

Each time you see duplicated logic, take the time to refactor it into a reusable function.

YAGNI - You Aren't Gonna Need It

Do not keep unused code such as variables, functions, implementations, etc.

Warning signs

Remove Unnecessary Comments

The following comment must be removed:

// Create a new task
createANewTask();

Other examples of inline comments that are obvious and must be removed:

// Validate that there is a file
if (!file) throw new ApiError(400);

// Validate and parse the request body according to the expected schema
const validated = UploadBodyAT.assert(body);

JSDoc comments should only be used when they add meaningful information. Example of a comment that must be entirely removed because everything is obvious:

/**
 * This function adds two numbers
 * @param a - The first number
 * @param b - The second number
 * @returns The sum of the two numbers
 */
function addTwoNumbers(a: number, b: number) {
  return a + b;
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.