typescript (error TS2322) : Type ‘{ type: ErrorPageType; }’ is not assignable to type ‘ErrorPageType.SIGNUP’

New to TS and am trying to create a Type which can then be passed as a prop from another component into this one like : <Error type={ErrorPageType.GENERIC}/> to conditionally render the correct view. Here is my code:

export enum ErrorPageType {
        ACCESS = "access",
        GENERIC = "generic",
        SIGNUP = "signup"
    }

interface ErrorProps {
    type?: ErrorPageType;
}

const getErrorType = (type?: ErrorPageType) {
    switch (type) {
        case ErrorPageType.ACCESS:
            return <AccessErrorPage />;
        case ErrorPageType.GENERIC:
            return <GenericErrorPage />;
        default:
            return <GenericErrorPage />;
    }
}

const ErrorPage = (type?: ErrorProps) => {
    return getErrorType(type)
};


export default ErrorPage;

I am getting the error: error TS2322: Type '{ type: ErrorPageType; }' is not assignable to type '(IntrinsicAttributes & ErrorPageType.ACCESS) | (IntrinsicAttributes & ErrorPageType.FSSO) | (IntrinsicAttributes & ErrorPageType.GENERIC) | (IntrinsicAttributes & ErrorPageType.SIGNUP)'. Type '{ type: ErrorPageType; }' is not assignable to type 'ErrorPageType.SIGNUP'. and I am not really sure why. Any help is much appreciated!



Read more here: https://stackoverflow.com/questions/67929895/typescript-error-ts2322-type-type-errorpagetype-is-not-assignable-to

Content Attribution

This content was originally published by HolyMoly at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: