Use for TypeScript style and type safety when editing TS/TSX/MTS, including imports, async code and error suppression.
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-typescript-f1a0cbc26aa4 ,按照其中的说明把「typescript」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
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 themimport { readFile } from 'fs/promises', never *Sync by default. Function coloring is asymmetric: async→sync migration is never needed, while sync→async (when IO gets slower, gains concurrency, or grows a subprocess/network call) forces rewriting every caller up the chain — sync-first debt that compounds. Micro-costs of async (thread-pool dispatch, cache races) are not valid reasons: races are solved by caching the promise instead of the result*Sync is acceptable in exactly one place: call sites locked inside a synchronous contract you don't control — an existing sync signature chain (don't virally refactor a legacy sync chain in a bugfix, but new standalone modules must not extend such chains), or sync-only callbacks like process.on('exit'). Module-load-time and CLI startup init are NOT exceptions — use top-level await (ESM) theresimple-import-sort/imports and consistent-type-imports with separate import type statements (fixStyle: 'separate-type-imports').export default — keeps refactor renames and IDE auto-import in sync, and avoids the default re-naming drift you get with import Foo from './foo'. Reserve export default for files where the framework requires it (Next.js page/route/layout, React.lazy targets, config files like vitest.config.ts). The codebase still has many export default occurrences — that's historical debt, not a pattern to copy; do not model new code on existing export default usage outside the framework-required cases abovepackages/utils and installed packages. Reuse @lobechat/utils or its relevant subpath instead of duplicating helpers across features.typeof value === 'object' && value !== null; import helpers like isRecord, isPlainRecord, isObjectLike, toRecord, pickString, UnknownRecord, etc. from @lobechat/utils/object.Date.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