Skip to main content

TypeScript & React

Casing Rules

ElementConventionExample
ClassesPascalCaseOrderService, UserRepository
InterfacesPascalCaseUserProfile, ApiResponse
Type aliasesPascalCaseUserId, OrderStatus
EnumsPascalCasePaymentMethod, UserRole
Enum membersPascalCasePaymentMethod.CreditCard
Functions / methodscamelCasegetUserById, processPayment
VariablescamelCaseuserCount, isActive
Boolean variablescamelCase with is/has/can prefixisLoading, hasPermission
ConstantsSCREAMING_SNAKE_CASEMAX_RETRY_COUNT, DEFAULT_TIMEOUT
React componentsPascalCaseUserProfile, OrderSummary

File Naming

# Classes and services — match the exported name:
UserService.ts
OrderController.ts
EmailValidator.ts

# React components — PascalCase, or index-based:
UserProfile.tsx
UserProfile/index.tsx

# Tests — mirror the source file:
UserService.test.ts
UserService.integration.test.ts
OrderWorkflow.e2e.test.ts

# Avoid:
userservice.ts # no casing
orderCtrl.ts # abbreviation
api.ts # no qualifier
test_userservice.ts # wrong convention for this ecosystem

Project Structure

src/
├── components/ # Reusable UI components
│ ├── common/
│ ├── forms/
│ └── layout/
├── services/ # Business logic and API clients
├── types/ # TypeScript type definitions
│ ├── api/
│ └── domain/
├── utils/ # Pure helper functions
└── hooks/ # Custom React hooks