Skip to content

Latest commit

 

History

History
82 lines (61 loc) · 2.25 KB

Naming.md

File metadata and controls

82 lines (61 loc) · 2.25 KB

Naming Style Guide

Variables

TypeScript

  1. PascalCase for name1
  2. camelCase for members1
  3. Do not use an I prefix for interfaces.1 Similarly, do not use a Type or Interface suffix to avoid conflicts with other entities (eg React components).
  4. Files containing only type definitions should go in a file camelCase file within a types directory.
  5. Attempt to group related types together into the same file as much as possible.
  6. When a type's member is an array don't define the type of the array's elements inline - define this separately.
Bad
type Positions = {
  start: number;
  end: number;
}[]
Good
type Position = {
  start: number;
  end: number;
}
type Positions = Position[]
  1. Use singular enum names. More generally, only use plural names for entities which are arrays.
Bad
enum Directions {
  Up,
  Down,
  Left,
  Right
}
Good
enum Direction {
  Up,
  Down,
  Left,
  Right
}

General

  1. DO choose easily readable identifier names. For example, a property named HorizontalAlignment is more English-readable than AlignmentHorizontal. 2

  2. DO favor readability over brevity. The property name CanScrollHorizontally is better than ScrollableX (an obscure reference to the X-axis). 2

  3. DO NOT use underscores, hyphens, or any other nonalphanumeric characters. 2

  4. 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

Files & Directories

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

References

  1. https://github.com/basarat/typescript-book/blob/master/docs/styleguide/styleguide.md
  2. https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/general-naming-conventions
  3. https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces