Skip to content

Commit c57ff0c

Browse files
feat: allow custom types with inner types (#278)
* feat: allow custom types with inner types * fix: concat multiple inner types
1 parent a631fee commit c57ff0c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ export const typify = (
255255
// we'll have to qualify it with the Node.js namespace.
256256
return 'NodeJS.ReadableStream';
257257
}
258+
// Custom type
259+
if (innerTypes)
260+
return `${typeAsString}<${innerTypes.map((innerType) => typify(innerType)).join(', ')}>`;
258261
return typeAsString;
259262
};
260263
export const paramify = (paramName: string) => {

test/utils.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ describe('utils', () => {
102102
it('should map node objects to the correct type', () => {
103103
expect(utils.typify('buffer')).toEqual('Buffer');
104104
});
105+
106+
it('should convert custom types with inner types', () => {
107+
expect(
108+
utils.typify({
109+
collection: false,
110+
innerTypes: [
111+
{
112+
collection: false,
113+
type: 'T',
114+
},
115+
],
116+
type: 'Foo',
117+
}),
118+
).toEqual('Foo<T>');
119+
120+
expect(
121+
utils.typify({
122+
collection: false,
123+
innerTypes: [
124+
{
125+
collection: false,
126+
type: 'A',
127+
},
128+
{
129+
collection: false,
130+
type: 'B',
131+
},
132+
],
133+
type: 'Foo',
134+
}),
135+
).toEqual('Foo<A, B>');
136+
});
105137
});
106138

107139
describe('paramify', () => {

0 commit comments

Comments
 (0)