I have an error with error on defaultState const:
interface AuthState<T = any> {
auth: T;
error: null | Error;
loading: boolean;
}
export const defaultState: { auth: null | AuthState } = {
auth: null,
error: null, // Here I got the error
loading: false
};
The error is:
TS2322: Type '{ auth: null; error: null; loading: boolean; }' is not assignable to type '{ auth: AuthState<any> | null; }'. Object literal may only specify known properties, and 'error' does not exist in type '{ auth: AuthState<any> | null; }'.
I can't get everything ok with types, any hint here?
defaultStateis an object with just one property namedauthwhich can be either of typeAuthStateor null. but you're adding properties likeloadinganderrorto your object.