跳到正文
cccskills
免费在 GitHub 公开

typescript

Guide for implementing TypeScript in projects, including naming conventions, type definitions, and code style. Triggered when writing or refactoring TypeScript code.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.1 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

TypeScript Development Guide

This skill provides mandatory specifications for writing TypeScript in this project to ensure consistency, type safety, and code cleanliness.

1. Naming Conventions

1.1 Variables and Functions

  • Variables: Use snake_case (e.g., theme_value, is_dev).
  • Functions: Use camelCase (e.g., getAntdTheme, setGlobalAnimation).
  • Internal Props Objects: Use props_* prefix (e.g., props_side_bar).

1.2 Classes and Types

  • Classes: Use PascalCase (e.g., GlobalModel, Settings).
  • Interfaces/Types: Use PascalCase. Interfaces preferably start with I (e.g., IProps, IPropsSidebar).
  • Enum-like Types: Use literal union types instead of enum where possible (e.g., type Theme = 'light' | 'dark' | 'system').

2. Type Definitions

2.1 File Organization

  • Global Types: Place in packages/app/types/ or packages/app/typings/.
  • Local Types: Use types.ts file in the component or module directory.
  • Props: Define an IProps interface for each component, typically in the component file or adjacent types.ts.

2.2 Best Practices

  • Explicit Types: Prefer providing explicit type annotations for function parameters and complex return value types.
  • Utility Types: Leverage TypeScript's utility types (Pick, Omit, Partial, Exclude) to reuse existing definitions.
  • Strict Types: Avoid any. If the type is truly unknown, use unknown and perform type casting (cast) when necessary.
  • Type Alias vs. Interface: Use interface for object structures (especially props), use type for unions, intersections, or base types.

3. Code Style

3.1 Imports and Exports

  • Named Exports: Utility functions and models prefer named exports.
  • Default Exports: For the main component or main class in a file, use default export.
  • Pure Type Imports: Use import type for importing types to maintain clear process boundaries and reduce bundle size.
  • Path Aliases: Use @/ to reference the src directory (e.g., import { Settings } from '@/models').

3.2 Statements and Logic

  • Arrow Functions: Component definitions and small utility functions prefer arrow functions.
  • Destructuring: Use destructuring for props and objects to improve readability.
  • Conditional Logic: Use optional chaining (?.) and nullish coalescing (??) for safer property access.

3.3 Code Spacing and Blank Lines

Use blank lines to separate code with different execution styles or visual appearances. If two adjacent lines of code look stylistically different, a blank line must be added between them.

When to Add Blank Lines:

  • Between data fetching and return statements
  • Between variable calculation and usage
  • Between multiple consecutive operations (different independent steps)
  • Before early returns
  • Between different operation types (sync vs async, query vs mutation)
  • Before and after state changes

Recommended:

async getSnapshot(weight_threshold = 0.2) {
	const nodes = await this.query(sql.sql_get_snapshot_nodes(weight_threshold))
	const edges = await this.query(sql.sql_get_snapshot_edges(weight_threshold))

	return { nodes, edges }
}

async tick(threshold_override?: number) {
	const threshold = threshold_override ?? 0.5

	await this.exec(sql.sql_tick(threshold))
}

Avoid:

async getSnapshot(weight_threshold = 0.2) {
	const nodes = await this.query(sql.sql_get_snapshot_nodes(weight_threshold))
	const edges = await this.query(sql.sql_get_snapshot_edges(weight_threshold))
	return { nodes, edges }
}

4. Summary Checklist

  • Are variable names snake_case?
  • Are function names camelCase?
  • Are component props using IProps or IProps*?
  • Are pure type imports using import type?
  • Are local types placed in types.ts files?
  • Has any been avoided in favor of strict types or unknown?
  • Are blank lines used to separate different execution style code blocks?

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Maintain package-level `agentmap.md` files as outline-level maps of the real file tree and core responsibilities. Use when package structure or responsibility boundaries change and the corresponding `agentmap.md` must be created or updated.

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

Guides the generation, reading, and updating of agentmap.md files. This skill ensures a consistent and up-to-date codebase map for AI Agents.

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

Interacts with local browser via Chrome DevTools Protocol (only triggered after user explicitly requests to inspect, debug, or interact with pages open in Chrome)

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

css

免费

Guides styling implementation using TailwindCSS + CSS Modules. Triggered when handling component styles, layout design, or CSS patterns.

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

Specialized for translating document files and their content into English. Triggered when localization, translation, or converting Chinese documents to English is requested.

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

Guides using eRPC (electron-tRPC) for inter-process communication (IPC) between Electron main and renderer processes. Triggered when handling Electron IPC or tRPC-based systems.

中文简介正在准备中。当前显示原文说明。

MatrixAges/polywise6622026年6月11日 更新

查看 MatrixAges 的全部技能

报告此技能的问题