TS2475

error TS2475: ‘const’ enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query.

Bad Code ❌

1
2
3
4
5
6
7
export const enum TIME_INTERVAL {
ONE_MINUTE = "1m",
THREE_MINUTES = "3m",
FIVE_MINUTES = "5m",
}

console.log(Object.values(TIME_INTERVAL));

Fixed Code ✔️

Defining a const enum prevents TypeScript from generating JavaScript code for this enum. With const enum TypeScript will just assume that the JavaScript equivalent of this code is already present.

If you want that TypeScript creates JS code for your enum definition, then you have to remove the const keyword:

1
2
3
4
5
6
7
export enum TIME_INTERVAL {
ONE_MINUTE = "1m",
THREE_MINUTES = "3m",
FIVE_MINUTES = "5m",
}

console.log(Object.values(TIME_INTERVAL));