| Id | ADN0008, the prefix of every message |
|---|---|
recommended | warn |
strict | error |
| Fixable | yes (--fix) |
| Needs type information | yes: 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
import { Contract, GreaterThan, Optional } from 'adorn';
@Contract()
class Forecast {
days(@Optional() @GreaterThan(0) days: number) {
return days ?? 3;
}
}
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 id | Text |
|---|---|
markedButRequired | [ADN0008] '{{name}}' is @{{marker}}() but required in TypeScript: no typed caller can omit it. Make it optional ('{{name}}?'), or drop the marker. |