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

Incomplete typing in crm.imports.coreApi.create prototype (HttpFile) #468

Open
madmatah opened this issue Feb 20, 2024 · 0 comments
Open

Comments

@madmatah
Copy link

Issue

I tried to use the Import contacts example from the README in a typescript project:

const file = {
    data: fs.createReadStream(fileName),
    name: fileName,
};
// [...]
const response = await  hubspotClient.crm.imports.coreApi.create(file, JSON.stringify(importRequest));

And I get the following type error:

error TS2740: Type 'ReadStream' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 97 more.

I think that the HttpFile type definition is incomplete, because in its current state it only expects to receive a Buffer:

export type HttpFile = {
    data: Buffer;
    name: string;
};

But the node-fetch library can accept many types in the request body.

Proposal

I suggest making at least this change:

export type HttpFile = {
    data: Buffer|ReadableStream;
    name: string;
};

But perhaps to be as complete as possible, the following change would be preferable:

export type HttpFile = {
    data: Buffer|ReadableStream|ArrayBuffer|ArrayBufferView|string;
    name: string;
};

Workaround:

In the meantime, I use the following (ugly) code, if it can help anyone experiencing the same problem. :

const file = {
    data: fs.createReadStream(fileName) as any,
    name: fileName,
};
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

1 participant