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

Error when running TSC in project with content api v2.1 reference #1736

Closed
nikmartin opened this issue Jun 13, 2019 · 4 comments · Fixed by #1757
Closed

Error when running TSC in project with content api v2.1 reference #1736

nikmartin opened this issue Jun 13, 2019 · 4 comments · Fixed by #1757
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@nikmartin
Copy link

Thanks for stopping by to let us know something could be better!

Environment details

  • OS: Linux
  • Node.js version: 10 LTS
  • npm version: 6.9.0
  • googleapis version: 40.0.0
  • typescript version: 3.5.1

Steps to reproduce

  1. Create a reference to content api, passing 'v2.1' as version
  2. run tsc

Here is the simplest reproduction of it:

package.json:

{
  "name": "contentapitest",
  "version": "1.0.0",
  "description": "test v2.1 of content api",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "google-auth-library": "^4.2.0",
    "googleapis": "^40.0.0"
  },
  "devDependencies": {
    "@types/node": "^10.14.0",
    "typescript": "^3.5.1"
  }
}

and index.js:

(async () => {
  const auth = new GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/content'],
  });
  let cli: OAuth2Client;
  try {
    cli = await auth.getClient();
  } catch (error) {
    return console.log(error);
  }

  const g = new GoogleApis();

  const content = g.content({ version: 'v2.1', auth: cli });
  const qryParam: any = { merchantId: '12345678', maxResults: 20, auth: cli };
  content.productstatuses.list().then((list) => {
    console.log(list);
  });
})();

Running npm i
and then tsc index.ts will trigger these errors:

index.ts:19:31 - error TS2322: Type '"v2.1"' is not assignable to type '"v2"'.

19   const content = g.content({ version: 'v2.1', auth: cli });
                                 ~~~~~~~
 node_modules/googleapis/build/src/apis/content/v2.d.ts:21:9
21         version: 'v2';
               ~~~~~~~
The expected type comes from property 'version' which is declared here on type 'Options'
Found 1 error.

and it will also crash at runtime with a similar error

@nikmartin
Copy link
Author

as an update, poking around in the content api d.ts files reveals that passing:
const content = g.content({ version: 'v2_1', auth: cli });
will cause the compile time error to go away, but causes a runtime crash:

(node:18495) UnhandledPromiseRejectionWarning: Error: Unable to load endpoint content("v2_1"): ctr is not a constructor
    at Object.getAPI (/home/nmartin/Projects/contentapitest/node_modules/googleapis-common/build/src/apiIndex.js:36:15)
    at GoogleApis.content (/home/nmartin/Projects/contentapitest/node_modules/googleapis/build/src/apis/content/index.js:24:32)
    at Object.<anonymous> (/home/nmartin/Projects/contentapitest/index.js:61:29)
    at step (/home/nmartin/Projects/contentapitest/index.js:32:23)
    at Object.next (/home/nmartin/Projects/contentapitest/index.js:13:53)
    at fulfilled (/home/nmartin/Projects/contentapitest/index.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Jun 14, 2019
@sduskis sduskis added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Jun 16, 2019
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Jun 16, 2019
@nikmartin
Copy link
Author

Any ideas here? This is a blocker to using the new 2.1 content api

@bcoe bcoe removed the triage me I really want to be triaged. label Jul 9, 2019
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Jul 9, 2019
@bcoe
Copy link
Contributor

bcoe commented Jul 11, 2019

@nikmartin mind taking googleapis@41.0.0 for a spin, I think it should address your bug 👍

@nikmartin
Copy link
Author

nikmartin commented Jul 11, 2019

@bcoe thanks, and this being a blocker was a bit hyperbolic, as I could pulled a compile time tscript ignore flag right above it and it would compile and run just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants