Skip to content

Commit

Permalink
feat: Default nestedKey to never
Browse files Browse the repository at this point in the history
  • Loading branch information
jungpaeng committed Oct 3, 2023
1 parent 6cc0ee6 commit efe6e10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-carrots-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-intl/core': patch
---

Default nestedKey to never
50 changes: 10 additions & 40 deletions packages/core/src/use-translation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IntlError, { IntlErrorCode } from './intl-error';
import { useIntlContext } from './intl.provider';
import { type RichTranslationValue, type TranslationValue, type Format } from './types';
import { type RichTranslationValue, type Format, type TranslationValue } from './types';
import { useTranslationImpl } from './use-translationImpl';
import { type MessageKey } from './utils/message-key';
import { type NamespaceKey } from './utils/namespace-key';
Expand All @@ -15,43 +15,23 @@ export function useTranslation<
// default translate function return type
<
TargetKey extends MessageKey<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>,
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>,
NestedKeyOf<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>
>
>,
>(
key: TargetKey,
value?: TranslationValue,
format?: Partial<Format>,
values?: TranslationValue,
formats?: Partial<Format>,
): string;

// translate.rich function return type
rich<
TargetKey extends MessageKey<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>,
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>,
NestedKeyOf<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>
>
>,
>(
Expand All @@ -63,19 +43,9 @@ export function useTranslation<
// translate.raw function return type
raw<
TargetKey extends MessageKey<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>,
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>,
NestedKeyOf<
NestedValueOf<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey
? '!'
: `!.${NestedKey}`
>
NestedValueOf<{ '!': IntlMessage }, [NestedKey] extends [never] ? '!' : `!.${NestedKey}`>
>
>,
>(
Expand All @@ -100,7 +70,7 @@ export function useTranslation<

return useTranslationImpl<
{ '!': IntlMessage },
NamespaceKey<IntlMessage, NestedKeyOf<IntlMessage>> extends NestedKey ? '!' : `!.${NestedKey}`
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
>(
{ '!': message },
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down

0 comments on commit efe6e10

Please sign in to comment.