How to write the store of mobx under typescript?

< H2 > Plan A: < / H2 >

directory structure:

store
  |--Auth
       |--index.ts
       |--interface.ts
  |--Bank
       |--index.ts
       |--interface.ts

Auth/interface.ts :

import {observable, action} from "mobx";
import {post} from "../../util/fetch";
import {IResponse} from "../../util/fetch";

class Auth {
  @observable
  isLogin:string = false;

  async loginWithNameAndPw({username, password}: {username: string, password: string}): Promise<IResponse> {
    try {
      const response = await post(`${userServer}/authz/oauth/token`);
      return response;
    } catch (e) {
      console.log(e);
      return e;
    }
  }

  async sendMsgCode({mobile}: {mobile: string}): Promise<IResponse> {
    try {
      const response = await post(`${userServer}/authz/sms/send`);
      return response;
    } catch (e) {
      console.log(e);
      return e;
    }
  }

}

const authStore = new Auth();
export default authStore;

should the type of members of class be separate from class (scheme A), or written with class (scheme B), or should I write both correctly?

Jun.27,2022

Plan B is fine. It is not recommended to separate


. I will choose option A

.
Menu