Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Vue-i18n arrays: Property does not exist on type 'never #1717

@DarkLite1

Description

@DarkLite1

Reporting a bug?

We created a simple landing page that displays countries defined in a Vue-i18n language.json file. This works fine but we get the following TypeScript errors:

[vue-tsc] Property 'code' does not exist on type 'never'.

[vue-tsc] Property 'name' does not exist on type 'never'.

It seems like the properties of a country are not found in the .json file. Although we did define the MessageSchema to be enUS, as described in the official documentation. For other strings in the lang.json files, there are no errors, only with a list or array it does not seem to default to String.

Please find a CodeSandBox for testing here. Below you can find the most important files.

File 'en-US.json'

 "page": {
    "landing": {
      "title": { "selectCountry": "Select your country" },
      "countries": [
        { "code": "BEL", "name": "Belgium" },
        { "code": "NLD", "name": "The Netherlands" }
      ]
    },

File '/boot/i18n.ts'

import enUS from 'src/i18n/en-US.json'
import nlBE from 'src/i18n/nl-BE.json'

export default boot(({ app }) => {
  // Type-define 'enUS' as the master schema for the resource
  type MessageSchema = typeof enUS

  const i18n = createI18n<[MessageSchema], 'en-US' | 'nl-BE'>({
    legacy: false,
    locale: Quasar.lang.getLocale(),
    fallbackLocale: 'en-US',
    messages: { 'en-US': enUS, 'nl-BE': nlBE },
  })

  app.use(i18n)
})

File 'LandingPage.vue'

<template>
  <q-page>
    <div>
      <q-card v-for="country in $tm('page.landing.countries')" :key="country.code">
        <q-card-section>
          <q-card-section>
            <div> {{ $rt(country.name) }} </div>
          </q-card-section>
        </q-card-section>
      </q-card>
    </div>
  </q-page>
</template>

This might be related to #91

Expected behavior

No TS errors

Reproduction

See this CodeSandBox for testing.

System Info

System:
    OS: Windows 10 10.0.20348
    CPU: (8) x64 Intel(R) Xeon(R) Gold 6242 CPU @ 2.80GHz
    Memory: 9.36 GB / 16.00 GB
  Binaries:
    Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.92)
    Internet Explorer: 11.0.20348.2520
  npmPackages:
    vite-plugin-checker: ^0.6.4 => 0.6.4 
    vue: ^3.4.18 => 3.4.23 
    vue-i18n: ^9.9.0 => 9.12.1 
    vue-router: ^4.0.12 => 4.3.0 
    vue-tsc: ^1.8.22 => 1.8.27

Screenshot

image

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions