Typescript Error: useContext is incompatible with index signature?

35 Views Asked by At

Having trouble trying to clear an error when building out an application.

type SelectedReportContext = {

    selectedReport: string | null;

    setSelectedReport: React.Dispatch<React.SetStateAction<string | null>>;

}

 

const SelectedReportContext = createContext<SelectedReportContext | undefined>(undefined)

 

export const useSelectedReportContext = () => {

    const onboardingContext = useContext(SelectedReportContext);

    if (onboardingContext === undefined) {

      throw new Error("useOnboardingContext must be inside a OnboardingProvider")

    }

    return onboardingContext

};

Here's the error

Type error: Type 'OmitWithTag<typeof import(""), "metadata" | "default" | "config" | "generateStaticParams" | "revalidate" | "dynamic" | ... 7 more ... | "generateViewport", "">' does not satisfy the constraint '{ [x: string]: never; }'.

  Property 'useSelectedReportContext' is incompatible with index signature.

    Type '() => SelectedReportContext' is not assignable to type 'never'.

   6 |

   7 | // Check that the entry is a valid entry

>  8 | checkFields<Diff<{

     |             ^

   9 |   default: Function

  10 |   config?: {}

  11 |   generateStaticParams?: Function

 ELIFECYCLE  Command failed with exit code 1.

I've tried toying around with the return type of the useSelectedReportContext function but couldn't seem to figure out the issue.

0

There are 0 best solutions below