Skip to content

Commit

Permalink
feat(keyset): allow to narrow the type of keyset keys (#33)
Browse files Browse the repository at this point in the history
* feat(keyset): allow to narrow the type of keyset keys

* feat: export KeysData type

* chore: move types
  • Loading branch information
ValeraS authored May 3, 2023
1 parent 666dd33 commit e2c0076
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {replaceParams} from './replace-params';
import {Logger, Params, PluralForm, Pluralizer} from './types';
import {Logger, Params, PluralForm, Pluralizer, KeysData, KeysetData} from './types';

import pluralizerEn from './plural/en';
import pluralizerRu from './plural/ru';

type KeysData = Record<string, string | string[]>;
type KeysetData = Record<string, KeysData>;

export * from './types';

export class I18N {
Expand Down Expand Up @@ -135,8 +132,8 @@ export class I18N {
return result;
}

keyset(keysetName: string) {
return (key: string, params?: Params): string => {
keyset<TKey extends string = string>(keysetName: string) {
return (key: TKey, params?: Params): string => {
return this.i18n(keysetName, key, params);
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export type KeysData = Record<string, string | string[]>;
export type KeysetData = Record<string, KeysData>;

type NoEnumLikeStringLiteral<T> = string extends T ? T : never;

export type I18NFn<T = any> = {
Expand Down

0 comments on commit e2c0076

Please sign in to comment.