ワンクリックで
typescript-best-practices
Use this skill when working with TypeScript code, type definitions, interfaces, generics, or async patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use this skill when working with TypeScript code, type definitions, interfaces, generics, or async patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
This skill should be used when the user asks to "run glab commands", "create a GitLab issue", "create a merge request", "check pipeline status", "manage GitLab projects", "create a release", or mentions glab, GitLab CLI, gitlab-cli, merge request, MR, GitLab pipeline, GitLab CI, GitLab issue keys, or gitlab operations via the command line.
Use this skill when the user asks about Conductor concepts, workflow patterns, track lifecycle, plan structures, or context-driven development principles. Also activate when working with conductor/ directory files or when implementing tasks following TDD and verification protocols.
This skill should be used when the user asks to "run acli jira commands", "create a Jira issue", "search Jira issues", "manage Jira projects", "transition Jira status", "check jira issue", "consistent with jira issue", or mentions ACLI, Atlassian CLI, Jira CLI, Jira issue keys (e.g. KAN-1, PROJ-123), or jira workitem/project/board/sprint operations via the command line.
Use this skill when working with Java code, Optional handling, CompletableFuture, records, sealed classes, or virtual threads.
Use this skill when designing or implementing REST APIs, endpoints, routes, or controllers.
Use this skill when writing tests, implementing TDD, or setting up test infrastructure.
| name | typescript-best-practices |
| description | Use this skill when working with TypeScript code, type definitions, interfaces, generics, or async patterns. |
| version | 1.0.0 |
Guidance for writing type-safe, maintainable TypeScript code. Covers type safety fundamentals, async/await patterns, and null handling strategies.
strict: true in tsconfig.jsonreadonly and const where possible// Good - interfaces are more extensible
interface User {
id: string;
name: string;
email: string;
}
// Use type for unions, intersections, mapped types
type UserRole = 'admin' | 'user' | 'guest';
type UserWithRole = User & { role: UserRole };
// Good - exhaustive pattern matching
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E };
function handleResult<T>(result: Result<T>) {
if (result.success) {
return result.data; // TypeScript knows data exists
}
throw result.error; // TypeScript knows error exists
}
any - Use unknown Instead// Bad
function processData(data: any) {
return data.value; // No type safety
}
// Good
function processData(data: unknown) {
if (isValidData(data)) {
return data.value; // Type narrowed via guard
}
throw new Error('Invalid data');
}
function isValidData(data: unknown): data is { value: string } {
return typeof data === 'object' && data !== null && 'value' in data;
}
// Good - constrained generics
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// Good - default type parameters
interface Repository<T extends { id: string } = { id: string }> {
findById(id: string): Promise<T | null>;
save(entity: T): Promise<T>;
}
// Good
async function fetchUser(id: string): Promise<User> {
try {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Failed to fetch user:', error);
throw error;
}
}
// Good - parallel execution
async function fetchUserData(userId: string) {
const [user, posts, comments] = await Promise.all([
fetchUser(userId),
fetchUserPosts(userId),
fetchUserComments(userId),
]);
return { user, posts, comments };
}
// Good - explicit return type
async function createUser(data: CreateUserDTO): Promise<User> {
const user = await db.users.create(data);
return user;
}
// Good - handle errors with Result type
async function safeCreateUser(data: CreateUserDTO): Promise<Result<User>> {
try {
const user = await db.users.create(data);
return { success: true, data: user };
} catch (error) {
return { success: false, error: error as Error };
}
}
// Good
const userName = user?.profile?.name ?? 'Anonymous';
const config = options?.timeout ?? DEFAULT_TIMEOUT;
// Avoid
const userName = user && user.profile && user.profile.name || 'Anonymous';
// OK when you've verified externally
const element = document.getElementById('root')!;
// Better - explicit check
const element = document.getElementById('root');
if (!element) {
throw new Error('Root element not found');
}
// Good - type guard function
function isDefined<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}
// Usage
const values = [1, null, 2, undefined, 3];
const defined = values.filter(isDefined); // number[]
undefined Over null for Optional// Good - consistent with optional properties
interface Options {
timeout?: number; // undefined when not set
retries?: number;
}
// Avoid mixing null and undefined
interface Options {
timeout: number | null; // Inconsistent
retries?: number;
}
// Make all properties optional
type PartialUser = Partial<User>;
// Make all properties required
type RequiredUser = Required<User>;
// Pick specific properties
type UserCredentials = Pick<User, 'email' | 'password'>;
// Omit specific properties
type PublicUser = Omit<User, 'password'>;
// Make properties readonly
type ImmutableUser = Readonly<User>;
// Record for object maps
type UserCache = Record<string, User>;
type AllRoles = 'admin' | 'user' | 'guest' | 'superadmin';
type AdminRoles = Extract<AllRoles, 'admin' | 'superadmin'>; // 'admin' | 'superadmin'
type NonAdminRoles = Exclude<AllRoles, 'admin' | 'superadmin'>; // 'user' | 'guest'
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true
}
}
strict: true enabled in tsconfig.jsonany types without documented justificationunknown instead of any for unknown data