Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any type definition for the promise returned? #100

Open
ahmedkamalio opened this issue Apr 15, 2019 · 0 comments
Open

Any type definition for the promise returned? #100

ahmedkamalio opened this issue Apr 15, 2019 · 0 comments

Comments

@ahmedkamalio
Copy link

Is there any type of definition for the promise returned?

for example

componentDidMount() {
    this.props.loadCategories().then(res => {
      // what is the type of res
    })
  }

I wanna represent the res with a typescript interface, so I came up with the following representation

/**
 * Describes the returned object of axios middleware action creators
 */
export interface IAxiosAction<TData = any> {
  type: string
  payload: {
    request: {
      client: string
      method: string
      url: string
    }
  }
}

/**
 * Describes the returned object of axios middleware calls
 */
export interface IAxiosResult<TData = any> {
  type: string
  payload: {
    config: IAxiosRequestConfig
    data: TData
    headers: { [key: string]: string }
    request: XMLHttpRequest
    status: number
    statusText: string
  }
  meta: {
    previousAction: IAxiosAction<TData>
  }
}

/**
 * Describes request config object of axios calls
 */
export interface IAxiosRequestConfig<TData = any> {
  adapter: any
  baseURL: string
  client: string
  data?: TData
  headers: { [key: string]: string }
  maxContentLength: number
  method: string
  reduxSourceAction: IAxiosAction<TData>
  responseType: string
  timeout: number
  transformRequest: any
  transformResponse: any
  url: string
  validateStatus: any
  xsrfCookieName: string
  xsrfHeaderName: string
}

Are the interfaces above really describes the res object? if so are you open to add .d.ts definition files to your source code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant