I have created a custom hook like this:
export const useCreateAccount: UseCreateAccountOutputs = () => {
...
return { error, loading, createAccount };
};
And I can correctly create the type like this:
type CreateAccountFn = () => Promise<void>;
type UseCreateAccountOutputs = () => {
loading: boolean;
error: string | null;
createAccount: CreateAccountFn;
};
However, I've created multiple custom hooks and don't want to repeat this all the time:
loading: boolean;
error: string | null;
I want to be able to create a type that extends this type:
export type CustomGraphqlHookOutputs = () => {
loading: boolean;
error: string | null;
};
How can I get this to work? I have tried this:
type UseCreateAccountOutputs = CustomGraphqlHookOutputs &
(() => {
createAccount: CreateAccountFn;
});
And this:
type UseCreateAccountOutputs = () => {
...CustomGraphqlHookOutputs,
createAccount: CreateAccountFn;
};
But neither work. Can someone let me know what I'm doing wrong?