Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom types with inner types #278

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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