hildjj / node-websequencediagrams

Call the WebSequenceDiagram.com API.
31 stars 18 forks source link

Typescript error TS2314 on diagram function type #14

Closed mikelax closed 2 years ago

mikelax commented 2 years ago

Overview

I am trying to use version 2.0.0 and I am getting a Typescript error when I try to build my project. The error is as follows:

node_modules/websequencediagrams/types/wsd.d.ts:33:83 - error TS2314: Generic type 'Array<T>' requires 1 type argument(s).

33     static diagram(description: string, style?: string, format?: string): Promise<Array<Buffer, string>>;

I get this error using both typescript 4.3.x and 4.4.x.

Fix

I think the fix is to make the Array take an implicit object of Buffer and string in the wsd.d.ts file. I believe this resolves the issue:

static diagram(description: string, style?: string, format?: string): Promise<Array<{diagram: Buffer, mimeType: string}>>;
hildjj commented 2 years ago

My goal is to have the types in the .js files be both legal jsdoc types as well as correct typescript types. I don't think that's possible here because jsdoc doesn't support tuples (see https://github.com/jsdoc/jsdoc/issues/1703).

My work-around was to use a simple Array in jsdoc, and hand-edit the .ts file with the proper tuple type.

Will this work for you?

mikelax commented 2 years ago

Hello @hildjj i think your initial goal would be great to have the types generated from jsdoc.

In this case I think your idea of (for now) hand editing the type file to solve this one case is correct.

Thank you for addressing!