Token导航 LogoToken导航TokenDH.com
开发规范需要联网github未标认证来源可访问clear审计未展示

typescript-best-practicesTypeScript 最佳实践

Agent Skill

typescript-best-practices 用于补充开发规范相关能力,适合在 Codex、Claude、Cursor、Gemini CLI 中需要让 Agent 承接开发规范相关任务时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

210

周安装

9

GitHub Stars

公开资料未说明

下载量

73
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:typescript-best-practices(TypeScript 最佳实践)
来源仓库:https://github.com/zatkniz/sporty-group
仓库路径:skills/typescript-best-practices
安装命令:
npx skills add zatkniz/sporty-group --skill "typescript-best-practices"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add zatkniz/sporty-group --skill "typescript-best-practices"

简介

typescript-best-practices 用于辅助 TypeScript 项目开发与维护,提供最佳实践指导。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中处理类型定义、代码规范和构建配置。
  • 通过 npx skills add 命令安装,需指定仓库和技能名称。
  • 安装前建议确认项目技术栈,避免引入不兼容的规范或工具链。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

name
typescript-best-practices
description
Enforce strict TypeScript standards including centralized type definitions in app/types/, arrow functions only, explicit return types, and lang="ts" in all components. Use when reviewing or creating TypeScript code.

TypeScript Best Practices

Enforce project-wide TypeScript standards and conventions.

When to Use

DO USE when:

  • Writing any new TypeScript code
  • Creating or modifying Vue components
  • Defining new types or interfaces
  • Creating composables or utilities
  • Reviewing code for TypeScript compliance
  • Refactoring JavaScript to TypeScript
  • Questions about type definitions
  • Type organization and structure

DO NOT USE when:

  • Dealing with plain JavaScript (convert to TypeScript first)
  • Configuration files that don't support TypeScript
  • Third-party type definitions (use @types packages)

Critical Standards

⚠️ NON-NEGOTIABLE RULES

  1. Type Location: ALL types MUST be in app/types/ directory

- ✅ import type { User } from '~/types/user' - ❌ Defining types inside components/composables

  1. Vue Components: ALWAYS use lang="ts"

- ✅ <script setup lang="ts"> - ❌ <script setup> without lang

  1. Function Style: ONLY arrow functions

- ✅ const myFunc = (): string => { ... } - ❌ function myFunc() { ... }

  1. Return Types: ALWAYS specify return types

- ✅ const getData = (): Promise<User[]> => { ... } - ❌ const getData = async () => { ... }

  1. Explicit Types: NO implicit any

- ✅ const items: Product[] = [] - ❌ const items = []

  1. Type Exports: ALWAYS export from app/types/

- ✅ All types exported and imported - ❌ Local type definitions

Type Organization Structure

Directory Layout

app/
  types/
    user.ts           # User-related types
    product.ts        # Product types
    api.ts            # API response types
    forms.ts          # Form data types
    state.ts          # State management types
    common.ts         # Shared/utility types
    errors.ts         # Error types
    index.ts          # Optional re-exports

File Naming

  • Use singular for entity types: user.ts, product.ts
  • Use descriptive names: api.ts, forms.ts, state.ts
  • Group related types in same file
  • Export all types from each file

Code Patterns

Component Pattern

// ✅ CORRECT
<script setup lang="ts">
import type { User, Product } from '~/types'

interface Props {
  user: User
  items: Product[]
}

const props = defineProps<Props>()

const formatName = (user: User): string => {
  return `${user.firstName} ${user.lastName}`
}
</script>

Composable Pattern

// ✅ CORRECT
// app/composables/useData.ts
import type { User, ApiResponse } from '~/types'

export const useData = () => {
  const data = ref<User | null>(null)
  
  const fetchData = async (): Promise<User> => {
    const { data: response } = await useFetch<ApiResponse<User>>('/api/user')
    if (!response.value) throw new Error('No data')
    return response.value.data
  }
  
  return { data, fetchData }
}

Store Pattern

// ✅ CORRECT
// app/stores/user.ts
import type { User, LoginCredentials } from '~/types'

export const useUserStore = defineStore('user', () => {
  const user = ref<User | null>(null)
  
  const login = async (creds: LoginCredentials): Promise<void> => {
    // Implementation
  }
  
  return { user: readonly(user), login }
})

Utility Pattern

// ✅ CORRECT
// app/utils/formatters.ts
import type { User, Product } from '~/types'

export const formatUser = (user: User): string => {
  return `${user.firstName} ${user.lastName}`
}

export const calculateTotal = (products: Product[]): number => {
  return products.reduce((sum: number, p: Product): number => 
    sum + p.price, 0
  )
}

Type Definition Patterns

Basic Entity Types

// app/types/user.ts
export interface User {
  id: string
  email: string
  firstName: string
  lastName: string
  role: UserRole
  createdAt: Date
}

export type UserRole = 'admin' | 'user' | 'guest'

API Response Types

// app/types/api.ts
export interface ApiResponse<T> {
  data: T
  message: string
  success: boolean
}

export interface PaginatedResponse<T> {
  items: T[]
  total: number
  page: number
}

Form Types

// app/types/forms.ts
export interface LoginForm {
  email: string
  password: string
}

export interface FormField<T> {
  value: T
  error: string | null
  touched: boolean
}

State Types

// app/types/state.ts
export interface LoadingState {
  isLoading: boolean
  error: Error | null
}

export interface DataState<T> extends LoadingState {
  data: T | null
}

Common Violations & Fixes

❌ Inline Type Definition

<!-- WRONG -->
<script setup lang="ts">
interface User {  // ❌ Type defined inline
  id: string
  name: string
}
</script>

Fix: Move to app/types/user.ts

❌ Missing Return Type

// WRONG
const getData = async () => {  // ❌ No return type
  return data
}

Fix: Add explicit return type

// CORRECT
const getData = async (): Promise<Data> => {
  return data
}

❌ Function Keyword

// WRONG
function handleClick() {  // ❌ function keyword
  // ...
}

Fix: Use arrow function

// CORRECT
const handleClick = (): void => {
  // ...
}

❌ Missing lang="ts"

<!-- WRONG -->
<script setup>  <!-- ❌ No lang="ts" -->
const data = ref()
</script>

Fix: Add lang="ts"

<!-- CORRECT -->
<script setup lang="ts">
const data = ref<string>('')
</script>

❌ Implicit Any

// WRONG
const items = []  // ❌ Implicit any[]
const user = ref()  // ❌ Implicit any

Fix: Add explicit types

// CORRECT
const items: string[] = []
const user = ref<User | null>(null)

Refactoring Checklist

When reviewing or refactoring TypeScript code:

  • [ ] All types defined in app/types/ directory
  • [ ] All Vue components use lang="ts"
  • [ ] All functions are arrow functions
  • [ ] All functions have explicit return types
  • [ ] No function keyword usage
  • [ ] No inline type definitions
  • [ ] No any types (use unknown if needed)
  • [ ] All variables have explicit types
  • [ ] Imports use import type for types
  • [ ] Generic types properly constrained

tsconfig Enforcement

Ensure these are enabled in tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true
  }
}

Quick Reference

✅ DO

  • Export all types from app/types/
  • Use lang="ts" in all Vue components
  • Use arrow functions exclusively
  • Specify return types on all functions
  • Use explicit types for all variables
  • Import types with import type
  • Use unknown instead of any
  • Document complex types with JSDoc

❌ DON'T

  • Define types inside components
  • Define types inside composables
  • Use function keyword
  • Omit return types
  • Use implicit any
  • Use any type
  • Define types in non-types files
  • Forget lang="ts" in components

Integration with Project

This TypeScript standard works with:

  • Components: lang="ts" + external types
  • Composables: Arrow functions + return types
  • Stores: Pinia with typed state/actions
  • Utils: Pure functions with explicit types
  • API: Typed requests/responses

Additional Resources

Example Workflow

User: "Create a user profile component"

  1. Define types in app/types/user.ts
  2. Create component with lang="ts"
  3. Import types: import type { User } from '~/types'
  4. Use arrow functions with return types
  5. Verify all TypeScript standards followed

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

weavefox

65.68%
按下载量换算48

Claude Code

28.18%
按下载量换算21

安全审计

暂无安全审计结果可展示。

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills