Skip to content

Commit

Permalink
feat: allow custom types with inner types (#278)
Browse files Browse the repository at this point in the history
* feat: allow custom types with inner types

* fix: concat multiple inner types
  • Loading branch information
samuelmaddock authored Oct 20, 2024
1 parent a631fee commit c57ff0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ export const typify = (
// we'll have to qualify it with the Node.js namespace.
return 'NodeJS.ReadableStream';
}
// Custom type
if (innerTypes)
return `${typeAsString}<${innerTypes.map((innerType) => typify(innerType)).join(', ')}>`;
return typeAsString;
};
export const paramify = (paramName: string) => {
Expand Down
32 changes: 32 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ 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<T>');

expect(
utils.typify({
collection: false,
innerTypes: [
{
collection: false,
type: 'A',
},
{
collection: false,
type: 'B',
},
],
type: 'Foo',
}),
).toEqual('Foo<A, B>');
});
});

describe('paramify', () => {
Expand Down

0 comments on commit c57ff0c

Please sign in to comment.