Skip to content

Commit 3b55d37

Browse files
authored
fix(types): allow spyOn of "useI18n()" (#1815)
1 parent 5be22a0 commit 3b55d37

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/vue-i18n-core/src/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export function useI18n<
742742
NonNullable<Options['messages']>,
743743
NonNullable<Options['datetimeFormats']>,
744744
NonNullable<Options['numberFormats']>,
745-
Options['locale'] extends unknown ? string : Options['locale']
745+
NonNullable<Options['locale']>
746746
>
747747

748748
export function useI18n<

test-dts/vue-i18n/i18n.test-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useI18n,
1111
createI18n
1212
} from '../../packages/vue-i18n-core/src/i18n'
13+
import * as vueI18n from '../../packages/vue-i18n-core/src/i18n'
1314
import { SchemaParams, LocaleParams } from '../../packages/core-base/src'
1415
import { ResourceSchema, MyDatetimeScehma, MyNumberSchema } from '../schema'
1516

@@ -505,3 +506,8 @@ expectType<{ zh: {}; 'ja-JP': { short: {} } }>(
505506
strictDirectI18n.datetimeFormats.value
506507
)
507508
expectType<{ ca: { currency: {} } }>(strictDirectI18n.numberFormats.value)
509+
510+
// allow mocking
511+
vi.spyOn(vueI18n, 'useI18n').mockReturnValue(<ReturnType<typeof useI18n>>{
512+
t: (key: string) => `{{${key}}}`
513+
})

0 commit comments

Comments
 (0)