Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create error.ts #1620

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Youngemmy5956
Copy link

Typescript error when using pluralization and formatting #1574

Typescript error when using pluralization and formatting intlify#1574
Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix the below type definition

export interface ComposerTranslation<
Messages extends Record<string, any> = {},
Locales = 'en-US',
DefinedLocaleMessage extends
RemovedIndexResources<DefineLocaleMessage> = RemovedIndexResources<DefineLocaleMessage>,
C = IsEmptyObject<DefinedLocaleMessage> extends false
? PickupPaths<{
[K in keyof DefinedLocaleMessage]: DefinedLocaleMessage[K]
}>
: never,
M = IsEmptyObject<Messages> extends false ? PickupKeys<Messages> : never,
ResourceKeys extends C | M = IsNever<C> extends false
? IsNever<M> extends false
? C | M
: C
: IsNever<M> extends false
? M
: never
> {
/**
* Locale message translation
*
* @remarks
* If this is used in a reactive context, it will re-evaluate once the locale changes.
*
* If [UseI18nScope](general#usei18nscope) `'local'` or Some [UseI18nOptions](composition#usei18noptions) are specified at `useI18n`, it’s translated in preferentially local scope locale messages than global scope locale messages.
*
* If not, then it’s translated with global scope locale messages.
*
* @param key - A target locale message key
*
* @returns Translated message
*
* @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope)
*/
<Key extends string>(key: Key | ResourceKeys | number): string
/**
* Locale message translation for plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, return a pluralized translation message.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param plural - Which plural string to get. 1 returns the first one.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
plural: number,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for missing default message
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, if no translation was found, return a default message.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param defaultMsg - A default message to return if no translation was found
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*/
<Key extends string>(
key: Key | ResourceKeys | number,
defaultMsg: string,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for list interpolations
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for list interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and return a pluralized translation message.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param plural - Which plural string to get. 1 returns the first one.
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
plural: number
): string
/**
* Locale message translation for list interpolations and missing default message
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, the locale messages should contain a `{0}`, `{1}`, … for each placeholder in the list, and if no translation was found, return a default message.
*
* @param key - A target locale message key
* @param list - A values of list interpolation
* @param defaultMsg - A default message to return if no translation was found
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
list: unknown[],
defaultMsg: string
): string
/**
* Locale message translation for named interpolations
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token.
*
* You can also suppress the warning, when the translation missing according to the options.
*
* About details of options, see the {@link TranslateOptions}.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
options?: TranslateOptions<Locales>
): string
/**
* Locale message translation for named interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and return a pluralized translation message.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param plural - Which plural string to get. 1 returns the first one.
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
plural: number
): string
/**
* Locale message translation for named interpolations and plurals
*
* @remarks
* Overloaded `t`. About details, see the [call signature](composition#key-key-resourcekeys-number-string) details.
*
* In this overloaded `t`, for each placeholder x, the locale messages should contain a `{x}` token, and if no translation was found, return a default message.
*
* @param key - A target locale message key
* @param named - A values of named interpolation
* @param defaultMsg - A default message to return if no translation was found
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
<Key extends string>(
key: Key | ResourceKeys | number,
named: NamedValue,
defaultMsg: string
): string
}
/**
* Resolve locale message translation functions
*
* @remarks
* This is the interface for {@link Composer}
*
* @VueI18nComposition
*/
export interface ComposerResolveLocaleMessageTranslation<Locales = 'en-US'> {
/**
* Resolve locale message translation
*
* @remarks
* If this is used in a reactive context, it will re-evaluate once the locale changes.
*
* If [UseI18nScope](general#usei18nscope) `'local'` or Some [UseI18nOptions](composition#usei18noptions) are specified at `useI18n`, it’s translated in preferentially local scope locale messages than global scope locale messages.
*
* If not, then it’s translated with global scope locale messages.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
*
* @returns Translated message
*
* @VueI18nSee [Scope and Locale Changing](../guide/essentials/scope)
*/
(message: MessageFunction<VueMessageType> | VueMessageType): string
/**
* Resolve locale message translation for plurals
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, return a pluralized translation message.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param plural - Which plural string to get. 1 returns the first one.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Pluralization](../guide/essentials/pluralization)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
plural: number,
options?: TranslateOptions<Locales>
): string
/**
* Resolve locale message translation for list interpolations
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, return a pluralized translation message.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param list - A values of list interpolation.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [List interpolation](../guide/essentials/syntax#list-interpolation)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
list: unknown[],
options?: TranslateOptions<Locales>
): string
/**
* Resolve locale message translation for named interpolations
*
* @remarks
* Overloaded `rt`. About details, see the [call signature](composition#message-messagefunction-message-message-string) details.
*
* In this overloaded `rt`, for each placeholder x, the locale messages should contain a `{x}` token.
*
* @VueI18nTip
* The use-case for `rt` is for programmatic locale messages translation with using `tm`, `v-for`, javascript `for` statement.
*
* @VueI18nWarning
* `rt` differs from `t` in that it processes the locale message directly, not the key of the locale message. There is no internal fallback with `rt`. You need to understand and use the structure of the locale messge returned by `tm`.
*
* @param message - A target locale message to be resolved. You will need to specify the locale message returned by `tm`.
* @param named - A values of named interpolation.
* @param options - Additional {@link TranslateOptions | options} for translation
*
* @returns Translated message
*
* @VueI18nSee [Named interpolation](../guide/essentials/syntax#named-interpolation)
*/
(
message: MessageFunction<VueMessageType> | VueMessageType,
named: NamedValue,
options?: TranslateOptions<Locales>
): string
}

@Youngemmy5956
Copy link
Author

will check it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants