# Typescript Standards · `TS`

Guidelines for all engineers writing TypeScript.

## Table of Contents

- [TypeScript Class Design Standards | TS-01](/standards/engineering/coding-standards/typescript/typescript-class-design#typescript-class-design-standards--ts-01)

  - [Types](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use type annotations for function parameters and return types | TS-01.1 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use type annotations variables of complex objects | TS-01.2 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use `const` over `let` for variables that do not change | TS-01.3 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use `unknown` over `any` | TS-01.4 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use `readonly` for properties that won't change after initialisation | TS-01.5 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
      - [`readonly` example (✅)](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use `undefined` over `null` | TS-01.6 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Use optional parameters | TS-01.7 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
    - [Avoid redundant type annotations when TypeScript can infer types | TS-01.8 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#types)
  - [Object-Oriented Programming](/standards/engineering/coding-standards/typescript/typescript-class-design#object-oriented-programming)
    - [Use interfaces to define object structures | TS-01.9 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#object-oriented-programming)
    - [Use classes to define objects | TS-01.10 | ](/standards/engineering/coding-standards/typescript/typescript-class-design#object-oriented-programming)

- [TypeScript Maintainability Standards | TS-02](/standards/engineering/coding-standards/typescript/typescript-maintainability#typescript-maintainability-standards--ts-02)

  - [Methods do not exceed 10 statements | TS-02.1 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#methods-do-not-exceed-10-statements)
  - [Do not duplicate code | TS-02.2 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#do-not-duplicate-code)
  - [Nested control statements do not exceed a depth of 2 | TS-02.3 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#nested-control-statements-do-not-exceed-a-depth-of-2)
  - [Do not allow methods with more than 4 parameters | TS-02.4 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#do-not-allow-methods-with-more-than-4-parameters)
  - [Do not use magic numbers or strings | TS-02.5 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#do-not-use-magic-numbers-or-strings)
  - [Use `Enum`s over fixed sets of constants | TS-02.6 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#use-enums-over-fixed-sets-of-constants)
  - [Allow gaps between numeric values for enums | TS-02.7 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#allow-gaps-between-numeric-values-for-enums)
  - [Don't comment out code | TS-02.8 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#dont-comment-out-code)
  - [Target specific versions or version ranges in `package.json` | TS-02.9 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#target-specific-versions-or-version-ranges-in-packagejson)
  - [Implement error logging for observability of problems | TS-02.10 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#implement-error-logging-for-observability-of-problems)
  - [Limit the contents of a source code file to one type | TS-02.11 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#limit-the-contents-of-a-source-code-file-to-one-type)
  - [Enable `strictNullChecks` for Type safety | TS-02.12 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#enable-strictnullchecks-for-type-safety)
  - [Optimise imports | TS-02.13 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#optimise-imports)
    - [Use relative imports | TS-02.14 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#optimise-imports)
    - [Configure aliases for improved readability | TS-02.15 | ](/standards/engineering/coding-standards/typescript/typescript-maintainability#optimise-imports)

- [TypeScript Naming Standards | TS-03](/standards/engineering/coding-standards/typescript/typescript-naming#typescript-naming-standards--ts-03)

  - [Files must follow the naming convention `{description}.{type}.{file extension}` | TS-03.1 | ](/standards/engineering/coding-standards/typescript/typescript-naming#files)
  - [The type within the file name should use the conventional names | TS-03.2 | ](/standards/engineering/coding-standards/typescript/typescript-naming#files)
  - [Symbols must use pascal case (`PascalCase`) | TS-03.3 | ](/standards/engineering/coding-standards/typescript/typescript-naming#symbols)
  - [Symbols must avoid private property prefix | TS-03.4 | ](/standards/engineering/coding-standards/typescript/typescript-naming#symbols)
  - [Components must use kebab case (`kebab-case`) | TS-03.5 | ](/standards/engineering/coding-standards/typescript/typescript-naming#components)
  - [The symbol must be suffixed with the word `Component` | TS-03.6 | ](/standards/engineering/coding-standards/typescript/typescript-naming#components)
  - [Component selectors should be prefixed to describe its use | TS-03.7 | ](/standards/engineering/coding-standards/typescript/typescript-naming#components)
  - [Directives must use camel case (`camelCase`) | TS-03.8 | ](/standards/engineering/coding-standards/typescript/typescript-naming#directives)
  - [The symbol must be suffixed with the word `Directive` | TS-03.9 | ](/standards/engineering/coding-standards/typescript/typescript-naming#directives)
  - [Directive selectors should be prefixed to describe its use | TS-03.10 | ](/standards/engineering/coding-standards/typescript/typescript-naming#directives)
  - [Pipes must use camel case (`camelCase`) | TS-03.11 | ](/standards/engineering/coding-standards/typescript/typescript-naming#pipe)
  - [The symbol must be suffixed with the word `Pipe` | TS-03.12 | ](/standards/engineering/coding-standards/typescript/typescript-naming#pipe)
  - [Pipe selectors should be prefixed to describe their use | TS-03.13 | ](/standards/engineering/coding-standards/typescript/typescript-naming#pipe)
  - [The symbol must be suffixed with the word `Module` | TS-03.14 | ](/standards/engineering/coding-standards/typescript/typescript-naming#module)
  - [Modules should be named after the feature and folder that they reside in | TS-03.15 | ](/standards/engineering/coding-standards/typescript/typescript-naming#module)

- [TypeScript Performance and Optimisation Standards | TS-04](/standards/engineering/coding-standards/typescript/typescript-performance-and-optimisation#typescript-performance-and-optimisation-standards--ts-04)
  - [Lazy load non-critical resources | TS-04.1 | ](/standards/engineering/coding-standards/typescript/typescript-performance-and-optimisation#lazy-load-non-critical-resources)

## Other Resources

- [General Test Automation Standards](/standards/engineering/engineering-principles/5-automated-testing/general-automation)

## Enforcement

In general, the [Airbnb standards](https://github.com/airbnb/javascript) are the basis for Typescript coding standards.

These are, where possible, enforced through the use of [ESLint](https://github.com/iamturns/eslint-config-airbnb-typescript). The [Audacia ESLint npm package](https://github.com/audaciaconsulting/Audacia.CodeAnalysis/tree/master/eslint/config/audacia-eslint-config) contains some default ESLint configuration for JavaScript and TypeScript projects.
