From 05f85436cb38ea015da2b0526b24c6871d54670a Mon Sep 17 00:00:00 2001 From: mrazauskas Date: Wed, 18 Jun 2025 14:34:37 +0300 Subject: [PATCH 1/3] chore: use `.toBeCallableWith()` in type test --- .../namespaceTranslation.test.ts | 46 +++++++------------ .../use-i18n/src/__typetests__/t.test.tsx | 24 ++++------ 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts b/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts index e365fedea..d9860737b 100644 --- a/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts +++ b/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts @@ -16,43 +16,33 @@ test('i18n - namespaceTranslation', () => { const { namespaceTranslation } = useI18n() // Single key - expect(namespaceTranslation('hello')).type.toRaiseError( - `Argument of type '"hello"' is not assignable to parameter of type '"doe" | "describe"'`, - ) - + expect(namespaceTranslation).type.not.toBeCallableWith('hello') // Multiple keys - expect(namespaceTranslation('doe.john')).type.toRaiseError( - `Argument of type '"doe.john"' is not assignable to parameter of type '"doe" | "describe"'`, - ) + expect(namespaceTranslation).type.not.toBeCallableWith('doe.john') expect(namespaceTranslation('doe')('john')).type.toBe() - expect(namespaceTranslation('doe')('doesnotexists')).type.toRaiseError( - `Expected 2 arguments, but got 1.`, - ) + expect(namespaceTranslation('doe')).type.not.toBeCallableWith('doesnotexists') // With a param - expect(namespaceTranslation('doe')('child')).type.toRaiseError( - `Expected 2 arguments, but got 1.`, - ) + expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child') expect( namespaceTranslation('doe')('child', { name: 'Name', }), ).type.toBe() - expect( - namespaceTranslation('doe')('doesnotexists', { + expect(namespaceTranslation('doe')).type.not.toBeCallableWith( + 'doesnotexists', + { name: 'Name', - }), - ).type.toRaiseError() - expect( - namespaceTranslation('doe')('child', { - doesnotexists: 'Name', - }), - ).type.toRaiseError() + }, + ) + expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', { + doesnotexists: 'Name', + }) - expect(namespaceTranslation('doe')('child', {})).type.toRaiseError() - expect(namespaceTranslation('doe')('child')).type.toRaiseError() + expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child', {}) + expect(namespaceTranslation('doe')).type.not.toBeCallableWith('child') // With multiple params expect( @@ -62,12 +52,10 @@ test('i18n - namespaceTranslation', () => { }), ).type.toBe() - expect(namespaceTranslation('describe')('john', {})).type.toRaiseError() - expect(namespaceTranslation('describe')('john')).type.toRaiseError() + expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john', {}) + expect(namespaceTranslation('describe')).type.not.toBeCallableWith('john') // Required generic const { namespaceTranslation: namespaceTranslation2 } = useI18n() - expect(namespaceTranslation2('test')).type.toRaiseError( - `Argument of type '"test"' is not assignable to parameter of type`, - ) + expect(namespaceTranslation2).type.not.toBeCallableWith('test') }) diff --git a/packages/use-i18n/src/__typetests__/t.test.tsx b/packages/use-i18n/src/__typetests__/t.test.tsx index 313ab59c8..2a3c697fc 100644 --- a/packages/use-i18n/src/__typetests__/t.test.tsx +++ b/packages/use-i18n/src/__typetests__/t.test.tsx @@ -12,11 +12,11 @@ const { t } = useI18n<{ test('i18n - t', () => { expect(t('hello')).type.toBe() // Single key - expect(t('keydoesnotexists')).type.toRaiseError() + expect(t).type.not.toBeCallableWith('keydoesnotexists') // Multiple keys expect(t('doe.john')).type.toBe() - expect(t('doe.doesnotexists')).type.toRaiseError() + expect(t).type.not.toBeCallableWith('doe.doesnotexists') // With a param expect( @@ -24,17 +24,13 @@ test('i18n - t', () => { name: 'Name', }), ).type.toBe() - expect( - t('doe.doesnotexists', { - name: 'Name', - }), - ).type.toRaiseError() + expect(t).type.not.toBeCallableWith('doe.doesnotexists', { + name: 'Name', + }) - expect(t('doe.child', {})).type.toRaiseError( - "Argument of type '{}' is not assignable to parameter of type", - ) + expect(t).type.not.toBeCallableWith('doe.child', {}) - expect(t('doe.child')).type.toRaiseError('Expected 2 arguments, but got 1') + expect(t).type.not.toBeCallableWith('doe.child') // With multiple params expect( @@ -44,8 +40,8 @@ test('i18n - t', () => { }), ).type.toBe() - expect(t('describe.john', {})).type.toRaiseError() - expect(t('describe.john')).type.toRaiseError() + expect(t).type.not.toBeCallableWith('describe.john', {}) + expect(t).type.not.toBeCallableWith('describe.john') // With react components as param value expect( @@ -60,5 +56,5 @@ test('i18n - t', () => { // Required generic const { t: t2 } = useI18n() - expect(t2('test')).type.toRaiseError() + expect(t2).type.not.toBeCallableWith('test') }) From a7510028704ac626ef477a23729e44749a9faa9d Mon Sep 17 00:00:00 2001 From: mrazauskas Date: Wed, 18 Jun 2025 14:46:47 +0300 Subject: [PATCH 2/3] bump version --- pnpm-lock.yaml | 12 ++++++------ pnpm-workspace.yaml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30e269576..257d934b0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -196,8 +196,8 @@ catalogs: specifier: 3.28.0 version: 3.28.0 tstyche: - specifier: 4.0.1 - version: 4.0.1 + specifier: 4.0.2 + version: 4.0.2 typescript: specifier: 5.8.3 version: 5.8.3 @@ -325,7 +325,7 @@ importers: version: 0.4.0 tstyche: specifier: 'catalog:' - version: 4.0.1(typescript@5.8.3) + version: 4.0.2(typescript@5.8.3) typescript: specifier: 'catalog:' version: 5.8.3 @@ -4537,8 +4537,8 @@ packages: tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tstyche@4.0.1: - resolution: {integrity: sha512-MnUxuObqIBwN7LZaLORFMm6dg6KSfkeCVGYXWhmcG6AFpFMQAgfpsIrt79NKw1VGHoThMJNAlffphsepe5Rzrw==} + tstyche@4.0.2: + resolution: {integrity: sha512-eACx04PtDZX9McRqyr+2So/o7uJSYEeNf7ljGZUSPncvdnUgJkSHfOuTs1JRse1DNcD+/3rYLX9sibqfIu6r0w==} engines: {node: '>=20.9'} hasBin: true peerDependencies: @@ -9386,7 +9386,7 @@ snapshots: tslib@2.8.1: {} - tstyche@4.0.1(typescript@5.8.3): + tstyche@4.0.2(typescript@5.8.3): optionalDependencies: typescript: 5.8.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index f84e70e9b..5ab68be9d 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -64,7 +64,7 @@ catalog: read-pkg: 9.0.1 shx: 0.4.0 simple-git: 3.28.0 - tstyche: 4.0.1 + tstyche: 4.0.2 typescript: 5.8.3 use-deep-compare-effect: 1.8.1 vite: 6.3.5 From b07866a689b998b19ee7117d88251a0303879f4f Mon Sep 17 00:00:00 2001 From: mrazauskas Date: Thu, 19 Jun 2025 08:09:21 +0300 Subject: [PATCH 3/3] clean up --- packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts b/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts index d9860737b..bfe760fd6 100644 --- a/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts +++ b/packages/use-i18n/src/__typetests__/namespaceTranslation.test.ts @@ -17,6 +17,7 @@ test('i18n - namespaceTranslation', () => { // Single key expect(namespaceTranslation).type.not.toBeCallableWith('hello') + // Multiple keys expect(namespaceTranslation).type.not.toBeCallableWith('doe.john')