Skip to content

TypeScript Style Guide

Sindre Reidar Mohr edited this page Aug 29, 2022 · 3 revisions

TypeScript Style Guide

Syntax

Identifiers

Must only use ASCII letters, digits and underscores.

UpperCamelCase: class, interface, type, enum, decorator, type parameters

lowerCamelCase: variable, parameter, function, method, property, module alias

CONSTANT_CASE: global constant values, including enum values

Abbreviations: Treat abbreviations like acronyms in names as whole words, i.e. use loadHttpUrl, not loadHTTPURL.

Type parameters: Type parameters, like in Array<T>, may use a single upper case character or UpperCamelCase.

Test names: Test method names may be structured with _ separators, e.g. testX_whenY_doesZ().

Comments & Documentation

Only use comments for interface parameter declaration. This is done using JSDoc /** ... */ comments. Methods and Variables should clearly indicate purpose/functionality in the given name.

Not allowed: const x:number = 12;

Allowed: const minimumPasswordLength:number = 12;

Clone this wiki locally