Add type argument to getSetting (https://github.com/woocommerce/woocommerce-blocks/pull/4361)
This commit is contained in:
parent
60b95041ff
commit
984c5a0eb1
|
@ -15,14 +15,14 @@ import { allSettings } from './settings-init';
|
||||||
* the `fallback` will be returned instead. An optional `filter`
|
* the `fallback` will be returned instead. An optional `filter`
|
||||||
* callback can be passed to format the returned value.
|
* callback can be passed to format the returned value.
|
||||||
*/
|
*/
|
||||||
export const getSetting = (
|
export const getSetting = < T >(
|
||||||
name: string,
|
name: string,
|
||||||
fallback: unknown = false,
|
fallback: unknown = false,
|
||||||
filter = ( val: unknown, fb: unknown ) =>
|
filter = ( val: unknown, fb: unknown ) =>
|
||||||
typeof val !== 'undefined' ? val : fb
|
typeof val !== 'undefined' ? val : fb
|
||||||
): unknown => {
|
): T => {
|
||||||
const value = name in allSettings ? allSettings[ name ] : fallback;
|
const value = name in allSettings ? allSettings[ name ] : fallback;
|
||||||
return filter( value, fallback );
|
return filter( value, fallback ) as T;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue