File tree Expand file tree Collapse file tree 5 files changed +54
-15
lines changed Expand file tree Collapse file tree 5 files changed +54
-15
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111} from '@intlify/shared'
1212import { HelperNameMap } from '@intlify/message-compiler'
1313import { Path } from './resolver'
14+ import { IsNever } from './types'
1415
1516type ExtractToStringKey < T > = Extract < keyof T , 'toString' >
1617type ExtractToStringFunction < T > = T [ ExtractToStringKey < T > ]
@@ -21,8 +22,38 @@ type StringConvertable<T> = ExtractToStringKey<T> extends never
2122 ? T
2223 : unknown
2324
25+ /**
26+ *
27+ * The interface used for narrowing types using generated types.
28+ *
29+ * @remarks
30+ *
31+ * The type generated by 3rd party (e.g. nuxt/i18n)
32+ *
33+ * @example
34+ * ```ts
35+ * // generated-i18n-types.d.ts (`.d.ts` file at your app)
36+ *
37+ * declare module '@intlify/core' {
38+ * interface GeneratedTypeConfig {
39+ * locale: "en" | "ja"
40+ * }
41+ * }
42+ * ```
43+ */
44+ export interface GeneratedTypeConfig { }
45+
46+ /**
47+ * Generated locale which resolves to `never` if left unset
48+ */
49+ export type GeneratedLocale =
50+ GeneratedTypeConfig extends Record < 'locale' , infer CustomLocale >
51+ ? CustomLocale
52+ : never
53+
2454/** @VueI 18nGeneral */
25- export type Locale = string
55+ export type Locale =
56+ IsNever < GeneratedLocale > extends true ? string : GeneratedLocale
2657
2758/** @VueI 18nGeneral */
2859// prettier-ignore
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export {
4242 MessageCompilerContext ,
4343 CompileError ,
4444 MessageContext ,
45- RemovedIndexResources
45+ RemovedIndexResources ,
46+ GeneratedTypeConfig
4647} from '@intlify/core-base'
4748export {
4849 VueMessageType ,
Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ import type {
109109 IsEmptyObject ,
110110 CoreMissingType ,
111111 JsonPaths ,
112- TranslationsPaths
112+ TranslationsPaths ,
113+ GeneratedLocale
113114} from '@intlify/core-base'
114115import type { VueDevToolsEmitter } from '@intlify/devtools-types'
115116
@@ -1274,11 +1275,13 @@ export interface Composer<
12741275 | PickupLocales < NonNullable < Messages > >
12751276 | PickupLocales < NonNullable < DateTimeFormats > >
12761277 | PickupLocales < NonNullable < NumberFormats > > ,
1277- Locales = OptionLocale extends Locale
1278- ? IsNever < ResourceLocales > extends true
1279- ? Locale
1280- : ResourceLocales
1281- : OptionLocale | ResourceLocales
1278+ Locales = Locale extends GeneratedLocale
1279+ ? GeneratedLocale
1280+ : OptionLocale extends Locale
1281+ ? IsNever < ResourceLocales > extends true
1282+ ? Locale
1283+ : ResourceLocales
1284+ : OptionLocale | ResourceLocales
12821285> extends ComposerCustom {
12831286 /**
12841287 * @remarks
Original file line number Diff line number Diff line change @@ -46,7 +46,8 @@ import type {
4646 PickupPaths ,
4747 PickupFormatPathKeys ,
4848 IsEmptyObject ,
49- IsNever
49+ IsNever ,
50+ GeneratedLocale
5051} from '@intlify/core-base'
5152import type { VueDevToolsEmitter } from '@intlify/devtools-types'
5253import type {
@@ -1047,11 +1048,13 @@ export interface VueI18n<
10471048 | PickupLocales < NonNullable < Messages > >
10481049 | PickupLocales < NonNullable < DateTimeFormats > >
10491050 | PickupLocales < NonNullable < NumberFormats > > ,
1050- Locales = OptionLocale extends string
1051- ? [ ResourceLocales ] extends [ never ]
1052- ? Locale
1053- : ResourceLocales
1054- : OptionLocale | ResourceLocales ,
1051+ Locales = Locale extends GeneratedLocale
1052+ ? GeneratedLocale
1053+ : OptionLocale extends string
1054+ ? [ ResourceLocales ] extends [ never ]
1055+ ? Locale
1056+ : ResourceLocales
1057+ : OptionLocale | ResourceLocales ,
10551058 Composition extends Composer <
10561059 Messages ,
10571060 DateTimeFormats ,
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ export {
5252 MessageCompilerContext ,
5353 CompileError ,
5454 MessageContext ,
55- RemovedIndexResources
55+ RemovedIndexResources ,
56+ GeneratedTypeConfig
5657} from '@intlify/core-base'
5758export {
5859 VueMessageType ,
You can’t perform that action at this time.
0 commit comments