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

GotRequest overloads don't obey resolveBodyOnly on instance #1822

Closed
2 tasks done
es50678 opened this issue Aug 6, 2021 · 1 comment
Closed
2 tasks done

GotRequest overloads don't obey resolveBodyOnly on instance #1822

es50678 opened this issue Aug 6, 2021 · 1 comment

Comments

@es50678
Copy link

es50678 commented Aug 6, 2021

Describe the bug

  • got version: 11.8.2
  • Node.js version: v14.17.1
  • OS & version: macOS Big Sur 11.5
  • typescript version: 4.3.5
  • tsconfig:
{
 "compilerOptions": {
   "lib": ["es2017"],
   "module": "commonjs",
   "target": "es2017",

   "strict": true,
   "esModuleInterop": true,
   "skipLibCheck": true,
   "forceConsistentCasingInFileNames": true,
   "declaration": true,
   "inlineSourceMap": true,
   "inlineSources": true
 }
}

When I create a got instance with resolveBodyOnly set to true, the type checker still things that the body is wrapped in a response.

Actual behavior

void (async () => {
  const jsonBodyClient = got.extend({
    responseType: 'json',
    resolveBodyOnly: true,
  });

  interface ResType {
    foo: string;
    bar: string;
  }

  const test = await jsonBodyClient<ResType>('issue/details');
  test.foo;
  //  => TS2339: Property 'foo' does not exist on type 'Response '.
})();

Expected behavior

void (async () => {
  const jsonBodyClient = got.extend({
    responseType: 'json',
    resolveBodyOnly: true,
  });

  interface ResType {
    foo: string;
    bar: string;
  }

  const test = await jsonBodyClient<ResType>('issue/details');
  test.foo; // should not throw typescript error
})();

Code to reproduce

void (async () => {
  const jsonBodyClient = got.extend({
    responseType: 'json',
    resolveBodyOnly: true,
  });

  interface ResType {
    foo: string;
    bar: string;
  }

  const test = await jsonBodyClient<ResType>('issue/details');
  test.foo;
  //  => TS2339: Property 'foo' does not exist on type 'Response '.
})();

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

Duplicate of #1117

@szmarczak szmarczak marked this as a duplicate of #1117 Aug 6, 2021
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

2 participants