Hello!
Didn't you think about some way to specify possible list of IDs?
For example:
// it is possible to build programmatically from your translations object, even nested
type AllowedIds = 'guests' | 'yes' | 'no'
const formatMessage = useGlobalize<AllowedIds>()
formatMessage('yes') // ok
formatMessage('maybe') // compile time error, not runtime
possible generic could be like that (orig code):
export interface Globalize<IDType extends string =string> extends GlobalizeConfig, GlobalizeHelpers, Formatters {
// ...
formatMessage(
id: IDType | IDType[],
values?: string[] | Record<string, string>,
options?: MessageFormatterOptions,
): string;
// second overload same way
// ...
It won't break code for users who don't use this generic (because the fallback is the old type: string).
It won't be useful for users who slash-combined ids: 'party/guests'. But I think than benefit gain worth it, because it makes the lib really type strong (strings are the weak place almost always).
So, for users who prefer to use complex paths (via slash), nothing is changed, meanwhile for users who don't want to rely on strings it would be a huge benefit.
Hello!
Didn't you think about some way to specify possible list of IDs?
For example:
possible generic could be like that (orig code):
It won't break code for users who don't use this generic (because the fallback is the old type:
string).It won't be useful for users who slash-combined ids:
'party/guests'. But I think than benefit gain worth it, because it makes the lib really type strong (strings are the weak place almost always).So, for users who prefer to use complex paths (via slash), nothing is changed, meanwhile for users who don't want to rely on strings it would be a huge benefit.