Skip to content

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

Description

@madmatah

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,
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions