mcpField
P
predictability

predictability

github.com/tossDevelopment2.0k51 installsUpdated 34w ago
Repository

About predictability

predictability is a skill for frontend developers focused on writing predictable code. It emphasizes making side effects explicit, using consistent return types for similar functions, and preserving existing API contracts.

Key features

  1. 01Move side effects to call sites
  2. 02Unify return types for similar functions
  3. 03Name functions to reflect behavior
  4. 04Preserve existing API contracts

Use cases

  1. 01Check getters for hidden operations
  2. 02Standardize results from validation functions
  3. 03Rename calculations that also save data

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/toss/frontend-fundamentals --skill predictability

After installing, type/predictabilityin Claude Code to confirm it loaded.

Details

From the project README

예측 가능성

함수는 이름이 암시하는 대로 동작해야 한다. 숨겨진 동작이 없어야 한다.

핵심 패턴

숨은 로직 드러내기

❌ fetch 함수에 숨은 부수 효과:

async function fetchBalance(): Promise<number> {
  const balance = await http.get<number>("...");
  logging.log("balance_fetched"); // 숨은 부수 효과!
  return balance;
}

✅ 부수 효과는 호출부에서 명시적으로:

async function fetchBalance(): Promise<number> {
  return await http.get<number>("...");
}

const balance = await fetchBalance();
logging.log("balance_fetched");
반환 타입 통일

❌ 같은 종류인데 반환 타입 다름:

function checkIsNameValid(name: string) {
  return name.length > 0; // boolean
}
function checkIsAgeValid(age: number) {
  if (age < 18) return { ok: false, reason: "18세 이상" };
  return { ok: true }; // 객체
}

✅ Discriminated Union으로 통일:

type ValidationResult = { ok: true } | { ok: false; reason: string };

function checkIsNameValid(name: string): ValidationResult {
  if (name.length === 0) return { ok: false, reason: "이름 필수" };
  return { ok: true };
}
function checkIsAgeValid(age: number): ValidationResult {
  if (age < 18) return { ok: false, reason: "18세 이상" };
  return { ok: true };
}

빠른 참조

코드 냄새개선 방법
getX()에 부수 효과순수 getter와 action 분리
calculateX()가 저장함calculateAndSaveX()로 이름 변경 또는 분리
같은 종류인데 반환 타입 다름Discriminated Union: { ok: true } | { ok: false; reason }
라이브러리 이름과 겹침구분되는 이름 사용: http → httpService

주의사항

  • 부수 효과를 제거하지 말고 명시적 위치로 이동
  • 지나치게 복잡한 타입 피하기
  • 기존 API 계약 유지

참고: https://frontend-fundamentals.com/code-quality/predictable/

Comments

Markdown supported