Skip to main content

Prefer usage of as const over literal type (prefer-as-const)

This rule recommends usage of const assertion when type primitive value is equal to type.

Rule Details

Examples of code for this rule:

let bar: 2 = 2;
let foo = <'bar'>'bar';
let foo = { bar: 'baz' as 'baz' };

When Not To Use It

If you are using TypeScript < 3.4


  • โœ… Recommended
  • ๐Ÿ”ง Fixable
  • ๐Ÿ’ญ Requires type information