Type definitions are wrong for REST helper
See original GitHub issueWhat are you trying to achieve?
Use the REST helper in a typescript project
What do you get instead?
Typescript compile errors because the provided type definitions for the REST helper do not match the actual method signatures.
The _executeRequest method and all of the send* methods are async and return the response object, however the type definition marks them as returning void. This means that in my code using these methods if I actually try to use the response object, typescript throws an error: Type 'void' is not assignable to type 'AxiosResponse<any>'
In addition, the arguments for each method are all marked as being required, even though most of them are optional, which means I have to pass undefined
for each argument to prevent typescript compiler errors.
Example showing both of the above issues
import { AxiosResponse } from 'axios';
const res: AxiosResponse = await this.sendPostRequest('', {});
helpers/steps_file.ts:46:13 - error TS2322: Type 'void' is not assignable to type 'AxiosResponse<any>'.
46 const res: AxiosResponse = await this.sendPostRequest('', {});
~~~
helpers/steps_file.ts:46:45 - error TS2554: Expected 3 arguments, but got 2.
46 const res: AxiosResponse = await this.sendPostRequest('', {});
~~~~~~~~~~~~~~~~~~~~~~~
Details
- CodeceptJS version: 2.6.10
- NodeJS Version: 14.11.0
- Operating System: Windows 10
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top GitHub Comments
@vdhpieter i guess the types are generated by jsdocs
So I managed to install the packages and I think I was trying something impossible. using the typing from Axios in the JSDoc. So for now I just made it return a
Promise<any>
which is not perfect but already better than justvoid