Skip to content

Commit

Permalink
fix: fix type params with default values in params table
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 14, 2021
1 parent 003cb96 commit 7d73eff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Expand Up @@ -45,6 +45,9 @@ function table(parameters: any) {
);
}
if (parameter.default) {
if (parameter.type) {
typeCol.push(' = ');
}
typeCol.push(Handlebars.helpers.type.call(parameter.default));
}
row.push(typeCol.join(''));
Expand Down
Expand Up @@ -56,6 +56,21 @@ exports[`Generics: should compile function with complex type params' 1`] = `
"
`;

exports[`Generics: should compile generics with defaults' 1`] = `
"▸ **genericsWithDefaults**: \`void\`
[partial: comment]
#### Type parameters
| Name | Type |
| :------ | :------ |
| \`Type\` | extends \`boolean\` = \`boolean\` |
[partial: member.sources]
"
`;

exports[`Generics: should compile type with nested generics' 1`] = `
"Ƭ **nestedGenerics**: [\`Generic1\`](../modules.md#generic1)<[\`Generic2\`](../modules.md#generic2)<[\`Generic3\`](../modules.md#generic3)<\`string\`\\\\>\\\\>\\\\>
Expand Down
10 changes: 10 additions & 0 deletions packages/typedoc-plugin-markdown/test/specs/generics.spec.ts
Expand Up @@ -64,4 +64,14 @@ describe(`Generics:`, () => {
),
).toMatchSnapshot();
});

test(`should compile generics with defaults'`, () => {
expect(
TestApp.compileTemplate(
declarationPartial,
testApp.findReflection('genericsWithDefaults')
.signatures[0] as SignatureReflection,
),
).toMatchSnapshot();
});
});
4 changes: 4 additions & 0 deletions packages/typedoc-plugin-markdown/test/stubs/src/generics.ts
Expand Up @@ -21,6 +21,10 @@ export const functionWithTypeParams = <
C = string,
>() => true;

export function genericsWithDefaults<Type extends boolean = boolean>() {
return;
}

export function functionWithGenericConstraints<Type, Key extends keyof Type>(
obj: Type,
key: Key,
Expand Down

0 comments on commit 7d73eff

Please sign in to comment.