xiaohongshu
xiaohongshu
js-ts-best-practices
JavaScript and TypeScript best practices covering naming conventions, control flow, state management, TypeScript patterns (avoid any/enum, prefer type over interface), safety (input validation, assertions, error handling), performance optimization (reduce branching/looping, memoization, defer awa...
Full skill instructions
Comprehensive coding standards and performance optimization guide for JavaScript and TypeScript applications, designed for AI agents and LLMs working with modern JavaScript/TypeScript codebases.
Use this skill when the task involves:
const vs let)any with proper types (unknown, generics)enum to as const objectstype and interfaceawait operations to avoid blockinglocalStorage, sessionStorage, or cookie readsDo not activate for:
This skill uses a progressive disclosure structure to minimize context usage:
Read AGENTS.md for a concise overview of all rules with one-line summaries organized by category.
When you identify a relevant pattern or issue, load the corresponding reference file for detailed implementation guidance:
General Best Practices:
TypeScript:
Safety:
Performance:
Documentation:
Each reference file contains:
Task: "This filter().map() chain is slow on large arrays"
Approach:
Before:
const result = items.filter(x => x.active).map(x => x.id);
After:
const result = items.reduce((acc, x) =>
x.active ? [...acc, x.id] : acc,
[]
);
any UsageTask: "Replace any types with proper TypeScript types"
Approach:
any with unknown or generics based on use caseBefore:
function process(data: any): any { /**/ }
After:
function process<T>(data: T): Result<T> { /**/ }
// or
function process(data: unknown): User { /**/ }
Task: "Make error messages more helpful for users"
Approach:
Before:
throw new Error('500');
After:
alert(
'We\'re having trouble connecting to our server.\n' +
'Please check your internet connection and try again.'
);
Task: "This function calls localStorage.getItem() 100 times in a loop"
Approach:
Before:
for (const item of items) {
const theme = localStorage.getItem('theme');
// ... 100 storage reads
}
After:
const storageCache = new Map();
function getCached(key) {
if (!storageCache.has(key)) {
storageCache.set(key, localStorage.getItem(key));
}
return storageCache.get(key);
}
for (const item of items) {
const theme = getCached('theme');
// ... 1 storage read
}
Task: "This random number function has GC pressure when called in a loop"
Approach:
Before:
function randomInt(min: number, max: number): number {
const minCeil = Math.ceil(min);
const maxFloor = Math.floor(max);
const range = maxFloor - minCeil + 1;
return Math.floor(Math.random() * range + minCeil);
}
After:
function randomInt(min: number, max: number): number {
const minCeil = Math.ceil(min);
const maxFloor = Math.floor(max);
return Math.floor(Math.random() * (maxFloor - minCeil + 1) + minCeil);
}
Task: "This round() function recomputes 10 ** precision on every call in a loop"
Approach:
Before:
export function round(precision: number, value: number): number {
const multiplier = 10 ** precision;
return Math.round(value * multiplier) / multiplier;
}
for (const price of prices) {
rounded.push(round(2, price)); // Recomputes 10 ** 2 every time
}
After:
export function round(precision: number): (value: number) => number;
export function round(precision: number, value: number): number;
export function round(
precision: number,
value?: number,
): number | ((value: number) => number) {
const multiplier = 10 ** precision;
if (value === undefined) {
return (v: number) => Math.round(v * multiplier) / multiplier;
}
return Math.round(value * multiplier) / multiplier;
}
const roundTo2 = round(2); // Compute once
for (const price of prices) {
rounded.push(roundTo2(price)); // Reuse precomputed multiplier
}
Design for performance from the start. Optimize slowest resources first:
network >> disk >> memory >> cpu
Always benchmark your assumptions before moving on. Premature optimization of CPU-bound operations while ignoring network bottlenecks wastes time.
const: Use let only for valid performance reasons[], {}, 0, '' instead of null/undefinedany: Use unknown for truly unknown types, generics for flexibilityenum: Use as const objects for better tree-shaking and type inferencetype: Use interface only for declaration merging or class contracts@param, @template, @returns@throws, @example (in addition to above)When optimizing performance:
Some patterns (like lookup tables) may seem to violate the "no premature optimization" principle. These are architectural choices, not optimizations:
This skill emphasizes "negative-space" or defensive programming:
The goal is correctness first, performance second.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience