quick-lint-js

Find bugs in JavaScript programs.

E0291: 'as const' is only allowed on literals (array, object, string, boolean) and enum members

In TypeScript, as const types an expression with a literal type. Expressions which can have literal types include the following:

It is an error to use as const on an expression which cannot have a literal type:

const DOCTYPE = html`<!DOCTYPE html>` as const;

To fix this error, remove as const:

const DOCTYPE = html`<!DOCTYPE html>`;

Alternatively, change the expression so it is valid with as const:

const DOCTYPE = `<!DOCTYPE html>` as const;

Introduced in quick-lint-js version 2.10.0.

Documentation for other errors