Skip to content

Commit a1ffa03

Browse files
api: improve typing of locale option key in exported keyed locale functions (#7967)
* improve typing of locale option key in exported functions * further type updateLocalOption using generics to enforce value type * use conditional typing to allow for better backwards compatibility * localeOption: use conditional typing or better backwards compatibility
1 parent 31641eb commit a1ffa03

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

components/lib/api/api.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ export declare function addLocale(locale: string, options: LocaleOptions): void;
720720
* @param {*} value - Option value.
721721
* @param {string} locale - Locale string.
722722
*/
723-
export declare function updateLocaleOption(key: string, value: any, locale: string): void;
723+
export declare function updateLocaleOption<Key extends keyof LocaleOptions>(key: Key, value: Key extends keyof LocaleOptions ? LocaleOptions[Key] : any, locale: string): void;
724+
export declare function updateLocaleOption<Key extends string>(key: Key, value: Key extends keyof LocaleOptions ? LocaleOptions[Key] : any, locale: string): void;
724725
/**
725726
* Changes the option values of a locale.
726727
* @param {LocaleOptions} options - Locale options.
@@ -732,6 +733,7 @@ export declare function updateLocaleOptions(options: object, locale: string): vo
732733
* @param {string} key - Option key.
733734
* @param {string} locale - Locale string.
734735
*/
736+
export declare function localeOption<Key extends keyof LocaleOptions>(key: Key, locale: string): LocaleOptions[Key];
735737
export declare function localeOption(key: string, locale: string): any;
736738
/**
737739
* Returns the values of locale options.

0 commit comments

Comments
 (0)