Skip to main content

TypeScript Constant

TypeScript use const to define a constant variable and readonly to define a constant class property.

Example

const UNIT_SUFFIXES = {
'milliseconds': 'ms',
'seconds': 's',
};


class Foo {
private static readonly MY_SPECIAL_NUMBER = 5;

bar() {
return 2 * Foo.MY_SPECIAL_NUMBER;
}
}

Naming

Use UPPER_SNAKE_CASE per google style guide

References