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.

@hubspot/api-client v8.0.0 typescript compile errors

See original GitHub issue

I’m trying to bump our @hubspot/api-client dependency to v8.0.0 from v7.1.2 and our webpack build fails with the updated dependency giving hundreds of errors like the following:

ERROR in ./node_modules/@hubspot/api-client/lib/src/discovery/webhooks/WebhooksDiscovery.d.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /home/rich/source/meetingplan/packages/server/node_modules/@hubspot/api-client/lib/src/discovery/webhooks/WebhooksDiscovery.d.ts. By default, ts-loader will not compile .ts files in node_modules.
You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option.
See: https://github.com/Microsoft/TypeScript/issues/12358
    at makeSourceMapAndFinish (/home/rich/source/meetingplan/packages/server/node_modules/ts-loader/dist/index.js:52:18)
    at successLoader (/home/rich/source/meetingplan/packages/server/node_modules/ts-loader/dist/index.js:39:5)
    at Object.loader (/home/rich/source/meetingplan/packages/server/node_modules/ts-loader/dist/index.js:22:5)
 @ ./node_modules/@hubspot/api-client/lib/src/discovery/ sync ^\.\/.*$ ./webhooks/WebhooksDiscovery.d.ts ./webhooks/WebhooksDiscovery.d
 @ ./node_modules/@hubspot/api-client/lib/src/services/initObject.js 5:26-57
 @ ./node_modules/@hubspot/api-client/lib/src/client.js 15:21-53
 @ ./node_modules/@hubspot/api-client/lib/index.js 4:15-38

Each error is for a different ./node_modules/@hubspot/api-client/lib/src/**/*.d.ts file.

On top of this, and possibly related, I’m seeing some APIs like client.crm.deals.searchApi.doSearch which used to return CollectionResponseWithTotalSimplePublicObjectForwardPaging, or client.crm.companies.batchApi.read which used to return BatchResponseSimplePublicObjectWithErrors are now returning any flagging new type errors in existing code.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

8reactions
akxcommented, Nov 23, 2022

@ksvirkou-hubspot FWIW, the work from #252 could be done in a (near-)type-safe, anyless way by using import type (which disappears at TypeScript compile time), e.g.

import type { WebhooksDiscovery } from './discovery/webhooks/WebhooksDiscovery'

and then typing the field as

protected _webhooks: WebhooksDiscovery | undefined

and making initObject generic (with an unfortunate pinky-swear as for the type):

import { IConfiguration } from '../configuration/IConfiguration'

export function initObject<T>(path: string, config: IConfiguration): T {
  const importedClass = require('../discovery/' + path)
  return new importedClass.default(config) as unknown as T;
}

and finally

  get webhooks() {
    if (!this._webhooks) {
      this._webhooks = initObject<WebhooksDiscovery>('webhooks/WebhooksDiscovery', this.config);
    }
    return this._webhooks
  }

(the latter may need a local for TS’s inference to work.)

2reactions
harry-peirsecommented, Nov 22, 2022

Hi, I am also seeing lots of typescript errors when trying to update. It appears a lot of the types are missing, or at least have been replaced by any. The client.d.ts file in my node_modules directory looks like this with 7.1.2:

export declare class Client {
    automation: AutomationDiscovery;
    cms: CmsDiscovery;
    communicationPreferences: CommunicationPreferencesDiscovery;
    conversations: ConversationsDiscovery;
    crm: CrmDiscovery;
    events: EventsDiscovery;
    marketing: MarketingDiscovery;
    oauth: OauthDiscovery;
    settings: SettingsDiscovery;
    webhooks: WebhooksDiscovery;
    config: IConfiguration;
    constructor(config?: IConfiguration);
    init(): void;
    setAccessToken(token: string): void;
    setApiKey(apiKey: string): void;
    setDeveloperApiKey(developerApiKey: string): void;
    apiRequest(opts?: IHttpOptions): Promise<import("node-fetch").Response>;
}

but with 8.0.0 it looks like this:

export declare class Client {
    config: IConfiguration;
    protected _automation: any;
    protected _cms: any;
    protected _communicationPreferences: any;
    protected _conversations: any;
    protected _crm: any;
    protected _events: any;
    protected _files: any;
    protected _marketing: any;
    protected _oauth: any;
    protected _settings: any;
    protected _webhooks: any;
    constructor(config?: IConfiguration);
    resetDiscoveries(): void;
    get automation(): any;
    get cms(): any;
    get communicationPreferences(): any;
    get conversations(): any;
    get crm(): any;
    get events(): any;
    get files(): any;
    get marketing(): any;
    get oauth(): any;
    get settings(): any;
    get webhooks(): any;
    setAccessToken(token: string): void;
    setApiKey(apiKey: string): void;
    setDeveloperApiKey(developerApiKey: string): void;
    apiRequest(opts?: IHttpOptions): Promise<import("node-fetch").Response>;
}

And this is leading to issues wherever we iterate on a collection, eslint is complaining that it doesn’t have enough type information, for example TS7006: Parameter 'hsOwner' implicitly has an 'any' type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HubSpot Library in Typescript and esModuleInterop
The solution to esModuleInterop errors reported by tsc for the HubSpot API library files is to add "esModuleInterop": true to tsconfig.json under the...
Read more >
Consider adding @types/request to dependencies #82 - GitHub
When I use @hubspot/api-client from TypeScript, I get compilation errors from tsc which complains that it doesn't understand what request is ...
Read more >
@hubspot/api-client - npm
Start using @hubspot/api-client in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >
Notice Report - Product documentation - NetApp
@typescript-eslint/eslint-plug in 1.7.1-alpha.31 ... apollo-client 2.6.10-test.0. MIT License ... blakeembrey/pluralize v8.0.0 MIT License.
Read more >
PickBazar - React Ecommerce Template with ... - ThemeForest
Buy PickBazar - React Ecommerce Template with React Hooks, Next JS, GraphQL & REST API by redqteam on ThemeForest. Our super-fast E-commerce ...
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