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

Unable to Instantiate a new Client class #986

Closed
danhlee329 opened this issue Sep 18, 2019 · 4 comments · Fixed by #1040
Closed

Unable to Instantiate a new Client class #986

danhlee329 opened this issue Sep 18, 2019 · 4 comments · Fixed by #1040
Labels
difficulty: easy fix is easy in difficulty type: bug bug in the library

Comments

@danhlee329
Copy link

danhlee329 commented Sep 18, 2019

Issue Summary

Currently I'm able to manually create client instances in javascript, but am not able to do so in Typescript.

Steps to Reproduce

import { Client } from '@sendgrid/client';
const clientInstance = new Client();

Error : Cannot use 'new' with an expression whose type lacks a call or construct signature.

Technical details:

  • @sendgrid/client Version: 6.4.0
  • Node.js Version: 10.16.3
@dfcowell
Copy link

dfcowell commented Dec 16, 2019

Also encountering this issue. Very frustrating for Typescript users.

Currently working around it with this nasty hack:

import { Client } from "@sendgrid/client";

import { ISendgridAccount } from "./ISendgridAccount";

const SGClient: any = Client;

export class SendgridClient {
  private client: typeof Client;

  constructor(account: ISendgridAccount) {
    this.client = new SGClient();

    this.client.setApiKey('');
  }
}

@manusis
Copy link

manusis commented Jan 8, 2020

We also need support for creating new instance of SendGrid/Mail fo a new API key. In Nodejs modules are singleton objects, so setApiKey would not work as it would cause race around conditions when multiple API keys are used.

@mgummelt
Copy link

I just ran into this problem as well. Would be great to get a fix. I'm pretty sure the problem is that this line:

declare const client: Client & { Client: Client }

Should instead read:

declare const client: Client & { Client: typeof Client }

@childish-sambino childish-sambino added difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library labels Feb 12, 2020
@childish-sambino
Copy link
Contributor

PR submitted to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty type: bug bug in the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants