I'm building a modal that is shared through the app with a Context, and the context returns a function that populate the modal and returns a promise.
The context declaration is:
const ConfirmerContext = createContext({
show: (options: {
title?: string;
description?: string;
cancelLabel?: string;
confirmLabel?: string;
colorScheme?: string;
}) => Promise<boolean>,
});
And the functions is:
function handleShow({
title = 'Title',
description = '',
cancelLabel = 'Cancel',
confirmLabel = 'Confirm',
colorScheme = 'blue',
}: {
title?: string;
description?: string;
cancelLabel?: string;
confirmLabel?: string;
colorScheme?: string;
}) {
setIsOpen(true);
setValues({
title,
description,
cancelLabel,
confirmLabel,
colorScheme,
});
return new globalThis.Promise<boolean>((resolve) => {
resolver.current = resolve;
});
}
resolver is a ref inside my component that i call on confirm or cancel of the modal.
The problem is that when i try to assign my handleShow inside the provider, like this:
<ConfirmerContext.Provider value={{ show: handleShow }}>
{children}
</ConfirmerContext.Provider>
I get the following error:
Type 'Promise<boolean>' is missing the following properties from type '{ new (executor: (resolve: (value: boolean | PromiseLike<boolean>) => void, reject: (reason?: any) => void) => void): Promise<boolean>; all<T>(values: Iterable<T | PromiseLike<T>>): Promise<...>; all<T extends readonly unknown[] | []>(values: T): Promise<...>; ... 6 more ...; readonly [Symbol.species]: PromiseConstr...': all, race, prototype, reject, and 4 more.