金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

typescript

typescript 是面向软件开发的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

TypeScript patterns specific to React components and hooks.

SKILL.md

下载 MD ↓
nameReact TypeScript
descriptionTypeScript patterns specific to React components and hooks.
metadata{"labels": ["react", "typescript", "types"], "triggers": {"files": ["**/*.tsx"], "keywords": ["ReactNode", "FC", "PropsWithChildren", "ComponentProps"]}}

React TypeScript

Priority: P1 (OPERATIONAL)

Type-safe React patterns.

Implementation Guidelines

  • Components: Return JSX.Element. Props interface over React.FC.
  • Children: Use ReactNode or PropsWithChildren<T>.
  • Events: React.ChangeEvent<HTMLInputElement>.
  • Hooks: useRef<HTMLDivElement>(null). useState<User | null>(null).
  • Props: Use ComponentProps<'button'> to mirror native els.
  • Generics: <T,>(props: ListProps<T>).
  • Polymorphism: as prop patterns.

Anti-Patterns

  • No any: Use unknown.
  • No React.FC: Implicit children is deprecated/bad practice.
  • No Function: Use (args: T) => void.

Code

// Modern Props
type ButtonProps = ComponentProps<'button'> & {
  variant?: 'primary' | 'secondary';
};

// Generic Component
type ListProps<T> = {
  items: T[];
  render: (item: T) => ReactNode;
};

function List<T>({ items, render }: ListProps<T>) {
  return <ul>{items.map(render)}</ul>;
}

// Hook Ref
const inputRef = useRef<HTMLInputElement>(null);

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本