Typescript Naming Standards

From bibbleWiki
Revision as of 00:13, 4 July 2025 by Iwiseman (talk | contribs) (Iwiseman moved page Typescript naming standards to Typescript Naming Standards)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

I guess I run with whatever the linter tells me but wanted to capture a way here

Naming Standards

Here we go

Type Convention Example
Variables camelCase const userName = "John";
Functions camelCase function calculateTotal() { ... }
Parameters camelCase function getUser(userId: string) { ... }
Classes PascalCase class UserAccount { ... }
Interfaces PascalCase interface UserProfile { ... }
Types PascalCase "inactive";
Enums PascalCase enum UserRole { Admin, Editor, Viewer }
Enum members PascalCase enum UserRole { Admin, Editor, Viewer }
Constants UPPER_SNAKE_CASE or camelCase const MAX_RETRY_ATTEMPTS = 3; or const apiEndpoint = "https://api.example.com";
Private properties camelCase with underscore prefix private _balance: number;
Public properties camelCase public name: string;
Namespace PascalCase namespace UserManagement { ... }
Generic type parameters Single uppercase letter or PascalCase <T> or <TItem>
File names kebab-case.ts user-profile.ts, auth-service.ts
React component files PascalCase.tsx UserProfile.tsx, LoginForm.tsx