From 9a11301c14119422c5e01f2c0646bd4a8ab614e6 Mon Sep 17 00:00:00 2001 From: Samuel Maddock Date: Wed, 2 Oct 2024 21:32:01 -0400 Subject: [PATCH 1/2] feat: allow custom types with inner types --- src/utils.ts | 2 ++ test/utils.spec.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index 4e5ed30..88c1ea8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -255,6 +255,8 @@ export const typify = ( // we'll have to qualify it with the Node.js namespace. return 'NodeJS.ReadableStream'; } + // Custom type + if (innerTypes) return `${typeAsString}<${typify(innerTypes[0])}>`; return typeAsString; }; export const paramify = (paramName: string) => { diff --git a/test/utils.spec.ts b/test/utils.spec.ts index e8a29e9..1293c79 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -102,6 +102,21 @@ describe('utils', () => { it('should map node objects to the correct type', () => { expect(utils.typify('buffer')).toEqual('Buffer'); }); + + it('should convert custom types with inner types', () => { + expect( + utils.typify({ + collection: false, + innerTypes: [ + { + collection: false, + type: 'T', + }, + ], + type: 'Foo', + }), + ).toEqual('Foo'); + }); }); describe('paramify', () => { From 75a867dcb8dec05218d1d79478e4372722497dda Mon Sep 17 00:00:00 2001 From: Samuel Maddock Date: Wed, 2 Oct 2024 21:43:59 -0400 Subject: [PATCH 2/2] fix: concat multiple inner types --- src/utils.ts | 3 ++- test/utils.spec.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 88c1ea8..ddc87ef 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -256,7 +256,8 @@ export const typify = ( return 'NodeJS.ReadableStream'; } // Custom type - if (innerTypes) return `${typeAsString}<${typify(innerTypes[0])}>`; + if (innerTypes) + return `${typeAsString}<${innerTypes.map((innerType) => typify(innerType)).join(', ')}>`; return typeAsString; }; export const paramify = (paramName: string) => { diff --git a/test/utils.spec.ts b/test/utils.spec.ts index 1293c79..733887f 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -116,6 +116,23 @@ describe('utils', () => { type: 'Foo', }), ).toEqual('Foo'); + + expect( + utils.typify({ + collection: false, + innerTypes: [ + { + collection: false, + type: 'A', + }, + { + collection: false, + type: 'B', + }, + ], + type: 'Foo', + }), + ).toEqual('Foo'); }); });