I've been having issues with this for a while. The code does run without issue, but I feel like I should figure out what TypeScript's linter is concerned about.
Here's the simplest repro I can get, LocaleConfig
is what gets the red highlight.
let Today = new Date();
let LocaleConfig = {dateStyle: "full"};
console.log(Today.toLocaleString([], LocaleConfig));
I've noticed that the linter has different errors depending on the target version. Here's the result from the default ES3.
No overload matches this call.
Overload 1 of 3, '(locales?: LocalesArgument, options?: DateTimeFormatOptions | undefined): string', gave the following error.
Argument of type '{ dateStyle: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
Types of property 'dateStyle' are incompatible.
Type 'string' is not assignable to type '\"full\" | \"long\" | \"medium\" | \"short\" | undefined'.
Overload 2 of 3, '(locales?: string | string[] | undefined, options?: DateTimeFormatOptions | undefined): string', gave the following error.
Argument of type '{ dateStyle: string; }' is not assignable to parameter of type 'DateTimeFormatOptions'.
{source: ts, code: 2769, severity: 8}
And here's from ES6. Error is on the same word.
Type '{ dateStyle: string; }' has no properties in common with type 'DateTimeFormatOptions'.
{source: ts, code: 2559, severity: 8}