← スキル一覧に戻る
Avoid

typescript-basics
by Joshua-Palamuttam
⭐ 0🍴 0📅 2025年12月8日
SKILL.md
name: typescript-basics description: TypeScript patterns for React including interfaces, type annotations, generics, null handling, and utility types. Use when writing type-safe React code.
TypeScript Basics
Overview
These TypeScript patterns ensure type-safe, maintainable React code. Follow these guidelines for all frontend development.
Interface Definitions
Data Model Interfaces
interface Task {
id: string;
title: string;
description: string | null;
isCompleted: boolean;
createdAt: string;
}
type TaskStatus = 'pending' | 'completed' | 'archived';
Request/Response Types
interface CreateTaskRequest {
title: string;
description?: string;
}
interface PagedResponse<T> {
items: T[];
page: number;
totalCount: number;
}
Type Annotations
Function Parameters
function handleClick(id: string): void {
console.log(id);
}
async function fetchTasks(): Promise<Task[]> {
const response = await fetch('/api/tasks');
return response.json();
}
State Types
const [tasks, setTasks] = useState<Task[]>([]);
const [error, setError] = useState<string | null>(null);
Event Handlers
function handleSubmit(e: React.FormEvent<HTMLFormElement>): void {
e.preventDefault();
}
function handleChange(e: React.ChangeEvent<HTMLInputElement>): void {
setValue(e.target.value);
}
Null and Undefined
Nullable Types
interface Task {
description: string | null; // Explicitly null
}
interface UpdateRequest {
title?: string; // Optional (undefined)
}
Null Checks
const title = task?.title ?? 'Untitled';
Utility Types
type TaskUpdate = Partial<Task>; // All optional
type TaskSummary = Pick<Task, 'id' | 'title'>; // Select props
type CreateTask = Omit<Task, 'id' | 'createdAt'>; // Exclude props
Best Practices
Avoid any
// Bad
function processData(data: any) { ... }
// Good
function processData(data: Task[]) { ... }
Export Types
export interface Task { ... }
import type { Task } from '../types/task';
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です