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:
- Array literals (e.g.
[],[first, second, third]) - Object literals (e.g.
{},{ key: value }) - String literals (e.g.
'','hello') - Untagged template literals (e.g.
``,`hello`) truefalse- Enum members (e.g.
LogLevel.DEBUG) - Any of the above wrapped in parentheses
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.