An official answer...
The problem occurs because
.weekday
is required to be one of"long" | "short" | "narrow"
but assigning the object literal to a variable first, with no further context, causes it to be widened tostring
, which TS then can't verify is compatible when you pass it to the function later. Passing the object literal directly works because contextual typing prevents the widening (i.e. TS can verify on the spot that you're passing a compatible string literal).
And a work around - use a JSdoc @type
hint...
/** @type {Intl.DateTimeFormatOptions} */
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };