@@ -7,18 +7,24 @@ import {
77 makeSymbol ,
88 warn
99} from '@intlify/shared'
10- import { effectScope , getCurrentInstance , inject , isRef , onMounted , onUnmounted } from 'vue'
10+ import { effectScope , inject , isRef , onMounted , onUnmounted } from 'vue'
1111import { createComposer } from './composer'
1212import { addTimelineEvent , enableDevTools } from './devtools'
1313import { I18nErrorCodes , createI18nError } from './errors'
1414import { apply as applyPlugin } from './plugin/next'
1515import { DisableEmitter , DisposeSymbol , EnableEmitter } from './symbols'
16- import { adjustI18nResources , getComponentOptions } from './utils'
16+ import { adjustI18nResources , getComponentOptions , getCurrentInstance } from './utils'
1717import { I18nWarnCodes , getWarnMessage } from './warnings'
1818
1919import type { FallbackLocale , Locale , LocaleParams , SchemaParams } from '@intlify/core-base'
2020import type { VueDevToolsEmitter , VueDevToolsEmitterEvents } from '@intlify/devtools-types'
21- import type { App , ComponentInternalInstance , EffectScope , InjectionKey } from 'vue'
21+ import type {
22+ App ,
23+ ComponentInternalInstance ,
24+ EffectScope ,
25+ GenericComponentInstance ,
26+ InjectionKey
27+ } from 'vue'
2228import type {
2329 Composer ,
2430 ComposerInternalOptions ,
@@ -136,17 +142,17 @@ export interface I18nInternal<
136142 OptionLocale = Locale
137143> {
138144 __instances : Map <
139- ComponentInternalInstance ,
145+ ComponentInternalInstance | GenericComponentInstance ,
140146 Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale >
141147 >
142148 __getInstance < Instance extends Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale > > (
143- component : ComponentInternalInstance
149+ component : ComponentInternalInstance | GenericComponentInstance
144150 ) : Instance | null
145151 __setInstance < Instance extends Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale > > (
146- component : ComponentInternalInstance ,
152+ component : ComponentInternalInstance | GenericComponentInstance ,
147153 instance : Instance
148154 ) : void
149- __deleteInstance ( component : ComponentInternalInstance ) : void
155+ __deleteInstance ( component : ComponentInternalInstance | GenericComponentInstance ) : void
150156 __composerExtend ?: ComposerExtender
151157}
152158
@@ -488,6 +494,7 @@ export function useI18n<
488494 throw createI18nError ( I18nErrorCodes . MUST_BE_CALL_SETUP_TOP )
489495 }
490496 if (
497+ // @ts -expect-error -- TODO(kazupon): need to fix types
491498 ! instance . isCE &&
492499 instance . appContext . app != null &&
493500 ! instance . appContext . app . __VUE_I18N_SYMBOL__
@@ -556,13 +563,15 @@ function createGlobal(options: I18nOptions): [EffectScope, Composer] {
556563 return [ scope , obj ]
557564}
558565
559- function getI18nInstance ( instance : ComponentInternalInstance ) : I18n {
566+ function getI18nInstance ( instance : ComponentInternalInstance | GenericComponentInstance ) : I18n {
560567 const i18n = inject (
568+ // @ts -expect-error -- TODO(kazupon): need to fix types
561569 ! instance . isCE ? instance . appContext . app . __VUE_I18N_SYMBOL__ ! : I18nInjectionKey
562570 )
563571 /* istanbul ignore if */
564572 if ( ! i18n ) {
565573 throw createI18nError (
574+ // @ts -expect-error -- TODO(kazupon): need to fix types
566575 ! instance . isCE ? I18nErrorCodes . UNEXPECTED_ERROR : I18nErrorCodes . NOT_INSTALLED_WITH_PROVIDE
567576 )
568577 }
@@ -588,12 +597,13 @@ function getGlobalComposer(i18n: I18n): Composer {
588597
589598function getComposer (
590599 i18n : I18n ,
591- target : ComponentInternalInstance ,
600+ target : ComponentInternalInstance | GenericComponentInstance ,
592601 useComponent = false
593602) : Composer | null {
594603 let composer : Composer | null = null
595604 const root = target . root
596- let current : ComponentInternalInstance | null = getParentComponentInstance ( target , useComponent )
605+ let current : ComponentInternalInstance | GenericComponentInstance | null =
606+ getParentComponentInstance ( target , useComponent )
597607 while ( current != null ) {
598608 const i18nInternal = i18n as unknown as I18nInternal
599609 composer = i18nInternal . __getInstance ( current )
@@ -610,7 +620,7 @@ function getComposer(
610620}
611621
612622function getParentComponentInstance (
613- target : ComponentInternalInstance | null ,
623+ target : ComponentInternalInstance | GenericComponentInstance | null ,
614624 useComponent = false
615625) {
616626 if ( target == null ) {
@@ -622,15 +632,17 @@ function getParentComponentInstance(
622632
623633function setupLifeCycle (
624634 i18n : I18nInternal ,
625- target : ComponentInternalInstance ,
635+ target : ComponentInternalInstance | GenericComponentInstance ,
626636 composer : Composer
627637) : void {
628638 let emitter : VueDevToolsEmitter | null = null
629639
630640 // eslint-disable-next-line vue-composable/lifecycle-placement -- NOTE(kazupon): not Vue component
631641 onMounted ( ( ) => {
632642 // inject composer instance to DOM for intlify-devtools
643+ // @ts -expect-error -- TODO(kazupon): need to fix types
633644 if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ && target . vnode . el ) {
645+ // @ts -expect-error -- TODO(kazupon): need to fix types
634646 target . vnode . el . __VUE_I18N__ = composer
635647 emitter = createEmitter < VueDevToolsEmitterEvents > ( )
636648 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -649,11 +661,14 @@ function setupLifeCycle(
649661 if (
650662 ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) &&
651663 ! __NODE_JS__ &&
664+ // @ts -expect-error -- TODO(kazupon): need to fix types
652665 target . vnode . el &&
666+ // @ts -expect-error -- TODO(kazupon): need to fix types
653667 target . vnode . el . __VUE_I18N__
654668 ) {
655669 emitter && emitter . off ( '*' , addTimelineEvent )
656670 _composer [ DisableEmitter ] && _composer [ DisableEmitter ] ( )
671+ // @ts -expect-error -- TODO(kazupon): need to fix types
657672 delete target . vnode . el . __VUE_I18N__
658673 }
659674 i18n . __deleteInstance ( target )
0 commit comments