nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.65k stars 465 forks source link

Support typed routes inside localePath() #2813

Open AndreyYolkin opened 4 months ago

AndreyYolkin commented 4 months ago

Describe the feature

According to the code here, nuxt i18n imports types from vue-router package: https://github.com/nuxt-modules/i18n/blob/c43842f11027253c07c45b7a9e8e6ab81bae7d54/src/runtime/composables/index.ts#L24

However, nuxt itself registers #vue-router alias to handle both situations with enabled/disabled typed routes. Example of usage: https://github.com/nuxt/nuxt/blob/d326e054d372bd2eb5bf75f3feca6a291169ff76/packages/nuxt/src/pages/runtime/utils.ts#L2

Since nuxt/i18n is a nuxt module, I suppose we can rely on this alias too and enable type imports by replacing vue-router with #vue-router for types imports

Additional information

Final checks

AndreyYolkin commented 4 months ago

As workaround, I added this snippet inside d.ts file and it works:

/// <reference types="unplugin-vue-router/client" />
import type { RouteLocation, RouteLocationNormalizedLoaded, RouteLocationRaw, Router } from '#vue-router';

declare module '#i18n' {
  export type StubbedLocalePathFunction = (route: RouteLocation | RouteLocationRaw, locale?: Locale) => string;

  export declare function useLocalePath(): StubbedLocalePathFunction;
}