Lint rule · ADN0008

adorn/no-optional-on-required

@Optional()/@Default() sits on a parameter TypeScript also lets a caller omit.

IdADN0008, the prefix of every message
recommendedwarn
stricterror
Fixableyes (--fix)
Needs type informationyes: a typed config (parserOptions.projectService)

What it reports

@Optional() or @Default() on a parameter TypeScript requires, such as @Optional() days: number.

Why

adorn would accept the omitted argument, but no typed caller can omit it, so the marker states an option the types never offer. The schema and docs then advertise a parameter as optional that TypeScript callers must always pass. It shares ADN0008 with optional-matches-ts and is a separate rule only so its severity can differ: a warning in recommended, an error in strict.

Examples

Reported

reported by adorn/no-optional-on-required
import { Contract, GreaterThan, Optional } from 'adorn';

@Contract()
class Forecast {
    days(@Optional() @GreaterThan(0) days: number) {
        return days ?? 3;
    }
}

Accepted

accepted
import { Contract, GreaterThan, Optional } from 'adorn';

@Contract()
class Forecast {
    days(@Optional() @GreaterThan(0) days?: number) {
        return days ?? 3;
    }
}

Details

The fix adds ? when every later parameter is optional too. When a required parameter follows, adding ? would not compile (TS1016), so the rule reports without a fix: drop the marker, or reorder the parameters.

To keep a finding on purpose, disable it with a reason, which justify-opt-out checks: // eslint-disable-next-line adorn/no-optional-on-required -- <why>.

Messages

The text ESLint prints, read from the rule itself. {{…}} is filled in for each finding.

Message idText
markedButRequired[ADN0008] '{{name}}' is @{{marker}}() but required in TypeScript: no typed caller can omit it. Make it optional ('{{name}}?'), or drop the marker.

All rules · the adorn/eslint guide