1 回答
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
初始狀態(tài)與返回的狀態(tài)類型不同。
export interface AuthenticationState {
isFetching: boolean;
user: User;
errors: Error[];
}
export const AuthenticationReducerDefaultState = {
errors: [], //Type never
isFetching: false,
user: {}, //Type {} not type User
};
你可以通過以下方式解決這個(gè)問題:
export interface AuthenticationState {
isFetching: boolean;
user: User | {}; //Note the union type
errors: Error[];
}
export const AuthenticationReducerDefaultState = <AuthenticationState>{
errors: [],
isFetching: false,
user: {},
};
//Also should freeze the state as you would not want accidental mutations.
export const AuthenticationReducerDefaultState = Object.freeze<AuthenticationState>({
errors: [],
isFetching: false,
user: {},
});
添加回答
舉報(bào)
