PascalCase
for name1camelCase
for members1- Do not use an
I
prefix for interfaces.1 Similarly, do not use aType
orInterface
suffix to avoid conflicts with other entities (eg React components). - Files containing only type definitions should go in a file
camelCase
file within atypes
directory. - Attempt to group related types together into the same file as much as possible.
- When a type's member is an array don't define the type of the array's elements inline - define this separately.
type Positions = {
start: number;
end: number;
}[]
type Position = {
start: number;
end: number;
}
type Positions = Position[]
- Use singular enum names. More generally, only use plural names for entities which are arrays.
enum Directions {
Up,
Down,
Left,
Right
}
enum Direction {
Up,
Down,
Left,
Right
}
-
DO choose easily readable identifier names. For example, a property named HorizontalAlignment is more English-readable than AlignmentHorizontal. 2
-
DO favor readability over brevity. The property name CanScrollHorizontally is better than ScrollableX (an obscure reference to the X-axis). 2
-
DO NOT use underscores, hyphens, or any other nonalphanumeric characters. 2
-
DO name classes and structs with nouns or noun phrases, using PascalCasing. This distinguishes type names from methods, which are named with verb phrases. 3
Extension/Type | Case |
---|---|
j|tsx |
PascaleCase (with JSX) |
j|ts |
camelCase (no JSX) |
json |
camelCase |
s?css |
kebab-case |
svg |
kebab-case |
directory | kebab-case |