Skip to content

feat: allow custom types with inner types #278

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

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])}>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

innerTypes is an array, we should technically do this for any number of inner types not just the first one. E.g. Foo<T, R> should be supported (I think the docs parser will read this)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. I tested with docs-parser and received multiple innerTypes (nice work btw!)

return typeAsString;
};
export const paramify = (paramName: string) => {
Expand Down
15 changes: 15 additions & 0 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>');
});
});

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