File tree Expand file tree Collapse file tree 4 files changed +52
-5
lines changed Expand file tree Collapse file tree 4 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,12 @@ export {
106106} from './legacy'
107107export { VERSION } from './misc'
108108export { I18nPluginOptions } from './plugin'
109- export { Disposer } from './types'
109+ export {
110+ Disposer ,
111+ GeneratedInstanceType ,
112+ GeneratedTypeConfig ,
113+ VueI18nInstance
114+ } from './types'
110115
111116export type {
112117 IsEmptyObject ,
Original file line number Diff line number Diff line change 1+ import type { IsNever } from '@intlify/core-base'
2+ import type { ExportedGlobalComposer } from './i18n'
3+ import type { VueI18n } from './legacy'
4+
15export type Disposer = ( ) => void
6+
7+ /**
8+ *
9+ * The interface used for narrowing types using generated types.
10+ *
11+ * @remarks
12+ *
13+ * The type generated by 3rd party (e.g. nuxt/i18n)
14+ *
15+ * @example
16+ * ```ts
17+ * // generated-i18n-types.d.ts (`.d.ts` file at your app)
18+ *
19+ * declare module '@intlify/vue-i18n-core' {
20+ * interface GeneratedTypeConfig {
21+ * legacy: false
22+ * }
23+ * }
24+ * ```
25+ */
26+ export interface GeneratedTypeConfig { }
27+
28+ /**
29+ * Narrowed i18n instance type based on `GeneratedTypeConfig['legacy']`
30+ *
31+ * - `never` (unset) resolves to `VueI18n | ExportedGlobalComposer`
32+ * - `true` resolves to `VueI18n`
33+ * - `false` resolves to `ExportedGlobalComposer`
34+ */
35+ export type GeneratedInstanceType =
36+ GeneratedTypeConfig extends Record < 'legacy' , infer Legacy > ? Legacy : never
37+
38+ /** @VueI 18nGeneral */
39+ export type VueI18nInstance =
40+ IsNever < GeneratedInstanceType > extends true
41+ ? VueI18n | ExportedGlobalComposer
42+ : GeneratedInstanceType extends true
43+ ? VueI18n
44+ : ExportedGlobalComposer
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ export {
125125} from '../../vue-i18n-core/src/legacy'
126126export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin'
127127export { VERSION } from './../../vue-i18n-core/src/misc'
128- export { Disposer } from './../../vue-i18n-core/src/types'
128+ export { Disposer , VueI18nInstance } from './../../vue-i18n-core/src/types'
129129
130130export type {
131131 IsEmptyObject ,
Original file line number Diff line number Diff line change @@ -21,14 +21,13 @@ import type {
2121 DefineDateTimeFormat ,
2222 DefineLocaleMessage ,
2323 RemovedIndexResources ,
24+ VueI18nInstance ,
2425 VueMessageType
2526} from '../../vue-i18n-core/src/composer'
26- import type { ExportedGlobalComposer } from '../../vue-i18n-core/src/i18n'
2727import type {
2828 DateTimeFormatResult ,
2929 NumberFormatResult ,
3030 TranslateResult ,
31- VueI18n ,
3231 VueI18nOptions
3332} from '../../vue-i18n-core/src/legacy'
3433
@@ -74,7 +73,7 @@ declare module 'vue' {
7473 * The locales, locale messages, and other resources managed by the instance referenced by this property are valid as global scope.
7574 * If the `i18n` component custom option is not specified, it's the same as the VueI18n instance that can be referenced by the i18n instance {@link I18n.global | global} property.
7675 */
77- $i18n : VueI18n | ExportedGlobalComposer
76+ $i18n : VueI18nInstance
7877 /**
7978 * Locale message translation
8079 *
You can’t perform that action at this time.
0 commit comments