Skip to content

TypeScript · correctness

no-union-in-comment

eslint:no-union-in-comment

Flag a comment that lists a `string` field's allowed values instead of the type listing them.

Default
error
Fix
none
Languages
typescript

Why

A comment cannot prevent callers from supplying strings outside the listed set, and the list can drift from runtime behavior.

Fix

Move the allowed values into a string-literal union and remove the redundant comment.

Before / after

Executed by this rule’s unit tests.

Before

Do not leave allowed values in a comment

src/record.ts · focus
interface R {
  kind: string; // 'aa' | 'bb'
}

After

Encode allowed values in the type

src/record.ts · focus
interface R { kind: 'aa' | 'bb'; }

Limits

  • Only bare quoted-value lists attached to supported string declarations and schema-builder fields are inspected.

Message IDs

unionInComment