Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
DarkLite1 opened this issue Oct 16, 2024 · 0 comments
Open
5 tasks done

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

DarkLite1 opened this issue Oct 16, 2024 · 0 comments
Labels
Status: Review Needed Request for review comments

Comments

@DarkLite1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review Needed Request for review comments
Projects
None yet
Development

No branches or pull requests

1 participant