Skip to content

Commit

Permalink
refactor(i18next): update the dependency to 23.15.1 accounting for ty…
Browse files Browse the repository at this point in the history
…pescript changes (#629)
  • Loading branch information
favna authored Sep 22, 2024
1 parent f730be1 commit f8b2f60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/i18next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@sapphire/utilities": "^3.17.0",
"@skyra/i18next-backend": "^2.0.5",
"chokidar": "^4.0.0",
"i18next": "^23.14.0"
"i18next": "^23.15.1"
},
"repository": {
"type": "git",
Expand Down
15 changes: 10 additions & 5 deletions packages/i18next/src/lib/InternationalizationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import i18next, {
type Namespace,
type ParseKeys,
type TFunction,
type TFunctionProcessReturnValue,
type TFunctionReturn,
type TFunctionReturnOptionalDetails,
type TOptions
Expand All @@ -17,7 +18,7 @@ import type { PathLike } from 'node:fs';
import { opendir } from 'node:fs/promises';
import { join } from 'node:path';
import { URL, fileURLToPath } from 'node:url';
import type { $Dictionary, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';
import type { $Dictionary, $NoInfer, $SpecialObject, InternationalizationContext, InternationalizationOptions } from './types';

/**
* A generalized class for handling `i18next` JSON files and their discovery.
Expand Down Expand Up @@ -259,14 +260,15 @@ export class InternationalizationHandler {
const TOpt extends TOptions = TOptions,
Ns extends Namespace = DefaultNamespace,
Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, undefined>, TOpt> = TOpt['returnObjects'] extends true ? $SpecialObject : string,
const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>
const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>,
DefaultValue extends string = never
>(
locale: string,
...[key, defaultValueOrOptions, optionsOrUndefined]:
| [key: Key | Key[], options?: ActualOptions]
| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: string }]
| [key: string | string[], defaultValue: string | undefined, options?: TOpt & $Dictionary]
): TFunctionReturnOptionalDetails<Ret, TOpt> {
| [key: string | string[], defaultValue: DefaultValue | undefined, options?: TOpt & $Dictionary]
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, DefaultValue>, TOpt> {
if (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');

const language = this.languages.get(locale);
Expand All @@ -279,7 +281,10 @@ export class InternationalizationHandler {
? language(this.options.defaultMissingKey, { replace: { key } })
: '';

return language<Key, TOpt, Ret, ActualOptions>(key, { defaultValue, ...((optionsOrUndefined ?? {}) as TOpt) });
return language<Key, TOpt, Ret, ActualOptions, DefaultValue>(key, {
defaultValue,
...((optionsOrUndefined ?? {}) as TOpt)
} as TOpt & $Dictionary & { defaultValue: DefaultValue });
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/i18next/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import type { ChokidarOptions } from 'chokidar';
import type { BaseInteraction, Guild, Interaction, LocalizationMap, Message, StageChannel, User, VoiceChannel } from 'discord.js';
import type { InitOptions } from 'i18next';

/**
* This is a re-exported type from i18next.
*
* We could use NoInfer typescript build-in utility,
* however this project still supports ts < 5.4.
*
* @see https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/NoInfer.ts
*/
export type $NoInfer<A> = [A][A extends any ? 0 : never];

/**
* This is a re-exported type from i18next.
* It is essentially an object of key-value pairs, where the key is a string and the value is any.
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ __metadata:
"@skyra/i18next-backend": "npm:^2.0.5"
chokidar: "npm:^4.0.0"
concurrently: "npm:^9.0.1"
i18next: "npm:^23.14.0"
i18next: "npm:^23.15.1"
tsup: "npm:^8.2.4"
tsx: "npm:^4.19.0"
typedoc: "npm:^0.25.13"
Expand Down Expand Up @@ -3953,12 +3953,12 @@ __metadata:
languageName: node
linkType: hard

"i18next@npm:^23.14.0":
version: 23.14.0
resolution: "i18next@npm:23.14.0"
"i18next@npm:^23.15.1":
version: 23.15.1
resolution: "i18next@npm:23.15.1"
dependencies:
"@babel/runtime": "npm:^7.23.2"
checksum: 10/661c1b22ae20bf75a616b3a804b96fd55bd04ed880853a05ef93912ed37f65b9546d8f8bbe55dfe2967a5b0f2ce110a7e9f4b7a6a3d90eb097d06c858d2b3e3f
checksum: 10/bfd4935517ddd68bd12ccc0b7bd454f1a19403b627d79a2fe81c9059380674f085804f8d7475dd248a887f90d9e2da0f9be64179ddf32e9eebac47e4b9f92889
languageName: node
linkType: hard

Expand Down

0 comments on commit f8b2f60

Please sign in to comment.