intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.14k stars 327 forks source link

Typescript error with custom composable after switching to pnpm #1323

Open sardor01 opened 1 year ago

sardor01 commented 1 year ago

Reporting a bug?

I have this composable that stores local messages:

import { type I18nScope, useI18n } from 'vue-i18n'

interface UseI18nSchema<T extends string = string> {
    message: Record<T, string | object>
}
type UseI18nLocale = (typeof localeOptions)[number]['id']

export const useTranslations = (props?: { scope?: I18nScope }) => {
  const { scope = 'global' } = props || {}

  const { t } = useI18n<UseI18nSchema, UseI18nLocale>({
    useScope: scope,
    messages: {
      en: {
        test: 'Test'
      },
      ru: {
        test: 'Тест'
      },
      uz: {
        test: 'Test'
      }
    }
  })

  return { t }
}

After I switched to pnpm, I started getting this error:

The inferred type of 'useTranslations' cannot be named without a reference to '.pnpm/@intlify+core-base@9.2.2/node_modules/@intlify/core-base'. This is likely not portable. A type annotation is necessary.ts(2742) image

Can someone explain why? Is it because I switched to pnpm or is there a problem with vue-i18n library itself?

Expected behavior

I expect not to have this error

Reproduction

https://github.com/Sardor01/vue-i18n-reproduction

System Info

System:
    OS: Linux 6.0 Pop!_OS 22.04 LTS
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 3.34 GB / 11.56 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.13.0/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
    pnpm: 7.26.3 - ~/.nvm/versions/node/v18.13.0/bin/pnpm
  Browsers:
    Chrome: 109.0.5414.119
    Firefox: 109.0
  npmPackages:
    @intlify/unplugin-vue-i18n: ^0.8.1 => 0.8.1 
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0 
    @vue/eslint-config-prettier: ^7.0.0 => 7.0.0 
    @vue/eslint-config-typescript: ^11.0.2 => 11.0.2 
    @vue/test-utils: ^2.2.8 => 2.2.8 
    @vue/tsconfig: ^0.1.3 => 0.1.3 
    vite: ^4.0.4 => 4.0.4 
    vitest: ^0.28.3 => 0.28.3 
    vue: ^3.2.45 => 3.2.45 
    vue-i18n: ^9.2.2 => 9.2.2 
    vue-router: ^4.1.6 => 4.1.6 
    vue-tsc: ^1.0.8 => 1.0.24 
    vue3-apexcharts: ^1.4.1 => 1.4.1

Screenshot

No response

Additional context

No response

Validations

JSoon commented 1 year ago

Sadly, I have the same trouble when generating declaration files.