Last active
September 30, 2021 19:12
-
-
Save panzi/d84a468e0b52469d9d7fecd706220aa3 to your computer and use it in GitHub Desktop.
Some missing types in axios for NodeJS (types would be different in browser).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import { IncomingMessage } from 'http'; | |
// browser version would use Uint8Array instead of Buffer and woudln't have stream/IncomingMessage | |
// since Buffer is a sub-class of Uint8Array you could use that in nodejs too, if you don't need any of the Buffer specific methods | |
declare module 'axios' { | |
interface AxiosInstance { | |
request(config: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
request(config: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
request(config: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
get(url: string, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
get(url: string, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
get(url: string, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
delete(url: string, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
delete(url: string, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
delete(url: string, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
head(url: string, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
head(url: string, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
head(url: string, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
options(url: string, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
options(url: string, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
options(url: string, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
post(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
post(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
post(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
put(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
put(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
put(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
patch(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'arraybuffer' }): Promise<AxiosResponse<Buffer>>; | |
patch(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'text' }): Promise<AxiosResponse<string>>; | |
patch(url: string, data?: any, config?: AxiosRequestConfig & { responseType: 'stream' }): Promise<AxiosResponse<IncomingMessage>>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment