question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS Error with datetimeFormats - TS2769: No overload matches this call.

See original GitHub issue

Reporting a bug?

TypeScript error in IDE on datetimeFormats, but application compiles normally and working properly.

Editor underlines the key datetimeFormats with red.

import messageDictionary from '@/i18n/messageDictionary'
import dateTimeFormats from '@/i18n/dateTimeFormats'

const i18n = createI18n({
  globalInjection: true,
  legacy: false,
  locale: 'ru',
  fallbackLocale: 'ru',
  availableLocales: ['ru', 'kz', 'en'],
  messages: messageDictionary(),
  datetimeFormats: dateTimeFormats()
})

Error details: TS2769: No overload matches this call.   Overload 1 of 2, ‘(options: I18nOptions<{ message: LocaleMessage<VueMessageType>; datetime: DateTimeFormat; number: NumberFormat; }, string, ComposerOptions<{ …; }, … 9 more …, NumberFormats<…>> | VueI18nOptions<…>>, LegacyVueI18n?: any): I18n<…>’, gave the following error.     Type ‘{ en: { short: { year: string; month: string; day: string; }; long: { year: string; month: string; day: string; weekday: string; hour: string; minute: string; hour12: boolean; }; }; ru: { short: { year: string; month: string; day: string; }; long: { …; }; }; kz: { …; }; }’ is not assignable to type ‘{ [x: string]: DateTimeFormat; }’.       Property ‘en’ is incompatible with index signature.         Type ‘{ short: { year: string; month: string; day: string; }; long: { year: string; month: string; day: string; weekday: string; hour: string; minute: string; hour12: boolean; }; }’ is not assignable to type ‘DateTimeFormat’.           Property ‘short’ is incompatible with index signature.             Type ‘{ year: string; month: string; day: string; }’ is not assignable to type ‘DateTimeFormatOptions’.               Type ‘{ year: string; month: string; day: string; }’ is not assignable to type ‘SpecificDateTimeFormatOptions’.                 Types of property ‘year’ are incompatible.                   Type ‘string’ is not assignable to type ‘DateTimeDigital | undefined’. vue-i18n.d.ts(731, 5): The expected type comes from property ‘datetimeFormats’ which is declared here on type ‘I18nOptions<{ message: LocaleMessage<VueMessageType>; datetime: DateTimeFormat; number: NumberFormat; }, string, ComposerOptions<{ message: LocaleMessage<…>; datetime: DateTimeFormat; number: NumberFormat; }, … 9 more …, NumberFormats<…>> | VueI18nOptions<…>>’

Expected behavior

No error messages from TS.

Reproduction

import { createApp } from 'vue'
import App from './App.vue'

import { createI18n } from 'vue-i18n'
import messageDictionary from '@/i18n/messageDictionary'
import dateTimeFormats from '@/i18n/dateTimeFormats'
const i18n = createI18n({
  globalInjection: true,
  legacy: false,
  locale: 'ru',
  fallbackLocale: 'ru',
  availableLocales: ['ru', 'kz', 'en'],
  messages: messageDictionary(),
  datetimeFormats: dateTimeFormats()
})

const app = createApp(App)
app.use(i18n).mount('#app')

System Info

Standard Vite vue-ts installation. MacOS. PHPStorm.

Most recent vue and vue-i18n versions.

Screenshot

No response

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
BlueBazzecommented, Feb 4, 2022

I came across this error as well. Following the documentation at https://vue-i18n.intlify.dev/guide/essentials/datetime.html#basic-usage

When inserting the datetimeFormats object directly in createI18n Like so

const i18n = createI18n({
  datetimeFormats: {
  "en-US": {
    short: {
      year: "numeric",
      month: "short",
      day: "numeric",
    },
    long: {
      year: "numeric",
      month: "short",
      day: "numeric",
      weekday: "short",
      hour: "numeric",
      minute: "numeric",
    },
  }
}
})

Works perfectly without any typescript errors. But following the documentation and having a const for datetimeFormats throws the error RollingTL gave above.

To fix the type error. Import the type I18nOptions and declare your datetimeFormat as so

const datetimeFormats: I18nOptions["datetimeFormats"] = {
  "en-US": {

And the error should disapear. Maybe the documentation for v9 could be updated to include a section for typescript that informs other users of this.

0reactions
savifoncommented, Jul 10, 2022

I came across this error as well. Following the documentation at https://vue-i18n.intlify.dev/guide/essentials/datetime.html#basic-usage

When inserting the datetimeFormats object directly in createI18n Like so

const i18n = createI18n({
  datetimeFormats: {
  "en-US": {
    short: {
      year: "numeric",
      month: "short",
      day: "numeric",
    },
    long: {
      year: "numeric",
      month: "short",
      day: "numeric",
      weekday: "short",
      hour: "numeric",
      minute: "numeric",
    },
  }
}
})

Works perfectly without any typescript errors. But following the documentation and having a const for datetimeFormats throws the error RollingTL gave above.

To fix the type error. Import the type I18nOptions and declare your datetimeFormat as so

const datetimeFormats: I18nOptions["datetimeFormats"] = {
  "en-US": {

And the error should disapear. Maybe the documentation for v9 could be updated to include a section for typescript that informs other users of this.

Thank you! It worked perfectly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error No overload matches this call TS2769 - Stack Overflow
Depends on what you want date to be if res.date is undefined. A possibility might be date: res && res.date && new Date(res.date)....
Read more >
Vue I18n does'nt work - Ionic Forum
[vue-cli-service] ERROR in src/i18n.ts:26:3 [vue-cli-service] TS2769: No overload matches this call. [vue-cli-service] Overload 1 of 2, ...
Read more >
No overload matches this call when trying to use array.reduce
I get the output I'm looking for, but typescript is yelling at me with this 700 line error message: No overload matches this...
Read more >
"No overload matches this call" - Airtable Community
I am trying to use createrecordsasync but am getting this error: “No overload matches this call” All the parameter types are correct.
Read more >
this syntax requires an imported helper named '__spreadarray'
error TS2769 : No overload matches this call. ... packages/ecma402-abstract/DateTimeFormat/BestFitFormatMatcher.ts#L128; error TS2322: Type '"best fit" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found