Enforce the use of as const over literal type.
There are two ways to indicate that a literal value should be interpreted as its literal type: as const and as with the literal type. The as const approach is recommended.
This rule applies only to .js and .ts files.
// code-linter.json5
{
"rules": {
"@typescript-eslint/prefer-as-const": "error"
}
} export const foo1 = 'bar';
export const foo2 = 'bar' as const;
export const foo3: 'bar' = 'bar' as const;
export const bar4 = 'bar' as string;
export const foo6 = { bar: 'baz' }; export const bar: 1 = 1;
export const foo1 = <'bar'>'bar';
export const foo2 = { bar: 'baz' as 'baz' }; plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.