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,
};
Issue
I tried to use the Import contacts example from the README in a typescript project:
And I get the following type error:
I think that the
HttpFiletype definition is incomplete, because in its current state it only expects to receive aBuffer:But the
node-fetchlibrary can accept many types in the request body.Proposal
I suggest making at least this change:
But perhaps to be as complete as possible, the following change would be preferable:
Workaround:
In the meantime, I use the following (ugly) code, if it can help anyone experiencing the same problem. :