⪼ Made with 💜 by Polyglot.
as constmeans the object cannot be maniuplated or changed
const LOG_LEVEL = {
DEBUG: 'DEBUG',
WARNING: 'WARNING',
ERROR: 'ERROR'
} as const;
The "as const" syntax in TypeScript is used to treat elements of an array or properties of an object as constants, i.e., their values cannot be changed. More importantly, it performs a type narrowing, indicating to the TypeScript compiler that the value should be inferred as narrowly as possible rather than its wider possible type.
const array = [1, 2, 3] as const; // The type is readonly [1, 2, 3], not number[]
const obj = { key: "value" } as const; // The type is { readonly key: "value" }, not { key: string }