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 {
106
106
} from './legacy'
107
107
export { VERSION } from './misc'
108
108
export { I18nPluginOptions } from './plugin'
109
- export { Disposer } from './types'
109
+ export {
110
+ Disposer ,
111
+ GeneratedInstanceType ,
112
+ GeneratedTypeConfig ,
113
+ VueI18nInstance
114
+ } from './types'
110
115
111
116
export type {
112
117
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
+
1
5
export 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 {
125
125
} from '../../vue-i18n-core/src/legacy'
126
126
export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin'
127
127
export { 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'
129
129
130
130
export type {
131
131
IsEmptyObject ,
Original file line number Diff line number Diff line change @@ -21,14 +21,13 @@ import type {
21
21
DefineDateTimeFormat ,
22
22
DefineLocaleMessage ,
23
23
RemovedIndexResources ,
24
+ VueI18nInstance ,
24
25
VueMessageType
25
26
} from '../../vue-i18n-core/src/composer'
26
- import type { ExportedGlobalComposer } from '../../vue-i18n-core/src/i18n'
27
27
import type {
28
28
DateTimeFormatResult ,
29
29
NumberFormatResult ,
30
30
TranslateResult ,
31
- VueI18n ,
32
31
VueI18nOptions
33
32
} from '../../vue-i18n-core/src/legacy'
34
33
@@ -74,7 +73,7 @@ declare module 'vue' {
74
73
* The locales, locale messages, and other resources managed by the instance referenced by this property are valid as global scope.
75
74
* 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.
76
75
*/
77
- $i18n : VueI18n | ExportedGlobalComposer
76
+ $i18n : VueI18nInstance
78
77
/**
79
78
* Locale message translation
80
79
*
You can’t perform that action at this time.
0 commit comments