第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

屬性“isFetching”在類型“never”上不存在,但在對象傳播時起作用

屬性“isFetching”在類型“never”上不存在,但在對象傳播時起作用

FFIVE 2022-08-04 10:06:28
為什么我收到下面代碼段的這個Typescript錯誤Property 'isFetching' does not exist on type 'never'.ts(2339)const mapStateToProps = (  state: AppState,  ownProps: AuthenticationPageProps): IMapStateToProps => ({  isFetching: state.authentication.isFetching,  user: state.authentication.user});但是,如果我傳播對象,它是否按預期工作?const mapStateToProps = (  state: AppState,  ownProps: AuthenticationPageProps): IMapStateToProps => {  const { isFetching, user } = state.authentication;  return { isFetching, user };};此代碼段也按預期工作:const mapStateToProps = (  state: AppState,  ownProps: AuthenticationPageProps): IMapStateToProps => ({  isFetching: state.authentication["isFetching"],  user: state.authentication["user"],});以下是我在打印時在開發(fā)人員工具中看到的內(nèi)容props這是接口IMapStateToPropsinterface IMapStateToProps {  isFetching: boolean;  user: User;}更多接口export interface AuthenticationState {  isFetching: boolean;  user: User;  errors: Error[];}export interface User {  email?: string;}export interface Error {  message: string;  status: string;}export const rootReducer = combineReducers({  authentication: authenticationReducer, // authenticationReducer returns type: AuthenticationState});export type AppState = ReturnType<typeof rootReducer>;
查看完整描述

1 回答

?
拉莫斯之舞

TA貢獻1820條經(jīng)驗 獲得超10個贊

初始狀態(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

};

你可以通過以下方式解決這個問題:


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: {},

});


查看完整回答
反對 回復 2022-08-04
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號