question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type definitions are wrong for REST helper

See original GitHub issue

What 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
PeterNgTrcommented, Jul 22, 2021

@vdhpieter i guess the types are generated by jsdocs

image

0reactions
vdhpietercommented, Jul 23, 2021

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 just void

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to overwrite incorrect TypeScript type definition installed ...
A way that is not mentioned here is to put a type declaration in a index.d.ts file. For my case, the types from...
Read more >
error TS2688: Cannot find type definition file for...random paths.
Basically anything that tries to do typescript gets a bunch of errors about not finding type definitions I never reference in any of...
Read more >
Incorrect typescript definition for Azure DevOps Services ...
If I make a call to `https://vsrm.dev.azure.com/jet-tfs/Kepler/_apis/release/definitions/317?api-version=5.0&$top=200` I can see that it's there but the ...
Read more >
A Pattern for Type-Safe REST API Requests in TypeScript
A Pattern for Type-Safe REST API Requests in TypeScript · 1. Define Endpoint · 2. Define JSON Schema · 3. Run JSON-TypeScript Type...
Read more >
Documentation - Narrowing - TypeScript
Understand how TypeScript uses JavaScript knowledge to reduce the amount of type syntax in your projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found