Skip to content

Commit

Permalink
fix(types): allow spyOn of "useI18n()" (#1815)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguet62 committed Apr 22, 2024
1 parent 5be22a0 commit 3b55d37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vue-i18n-core/src/i18n.ts
Expand Up @@ -742,7 +742,7 @@ export function useI18n<
NonNullable<Options['messages']>,
NonNullable<Options['datetimeFormats']>,
NonNullable<Options['numberFormats']>,
Options['locale'] extends unknown ? string : Options['locale']
NonNullable<Options['locale']>
>

export function useI18n<
Expand Down
6 changes: 6 additions & 0 deletions test-dts/vue-i18n/i18n.test-d.ts
Expand Up @@ -10,6 +10,7 @@ import {
useI18n,
createI18n
} from '../../packages/vue-i18n-core/src/i18n'
import * as vueI18n from '../../packages/vue-i18n-core/src/i18n'
import { SchemaParams, LocaleParams } from '../../packages/core-base/src'
import { ResourceSchema, MyDatetimeScehma, MyNumberSchema } from '../schema'

Expand Down Expand Up @@ -505,3 +506,8 @@ expectType<{ zh: {}; 'ja-JP': { short: {} } }>(
strictDirectI18n.datetimeFormats.value
)
expectType<{ ca: { currency: {} } }>(strictDirectI18n.numberFormats.value)

// allow mocking
vi.spyOn(vueI18n, 'useI18n').mockReturnValue(<ReturnType<typeof useI18n>>{
t: (key: string) => `{{${key}}}`
})

0 comments on commit 3b55d37

Please sign in to comment.