TypeScript code style and optimization guidelines. MUST READ before writing or modifying any TypeScript code (.ts, .tsx, .mts files). Also use when reviewing code quality or implementing type-safe patterns. Triggers on any TypeScript file edit, code style discussions, or type safety questions.
any; explicitly type when necessaryRecord<PropertyKey, unknown> over object or anyinterface for object shapes (e.g., React props); use type for unions/intersectionsas const satisfies XyzInterface over plain as const@ts-expect-error over @ts-ignore over as anydeclare module '...') over namespace; do not introduce namespace-based extension patternsPipelineContext.metadata, define the metadata fields next to the processor/provider/plugin that reads or writes themasync/await over callbacks or .then() chains*Sync)import { readFile } from 'fs/promises'Promise.all, Promise.race for concurrent operations where safesimple-import-sort/imports and consistent-type-imports (fixStyle: 'separate-type-imports')import type { ... } for type-only imports, NOT import { type ... } inline syntaximport type { ... } from a package and you need to add a value import, keep them as two separate statements:
import type { ChatTopicBotContext } from '@lobechat/types';
import { RequestTrigger } from '@lobechat/types';
@lobehub/ui, Ant Design components instead of raw HTML tagsantd-style token system instead of hard-coded colorsfor…of loops over index-based for loopspackages/utils or installed npm packagesDate.now() to a constant once and reuse for consistencyimport { log } from 'debug' directly (logs to console)console.error in catch blocks instead of debug package.catch() callbacks — silent .catch(() => fallback) swallows failures and makes debugging impossible