Skip to content

Commit

Permalink
fix: expand generic object (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Nov 19, 2021
1 parent 6f755e8 commit 5029a85
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
Expand Up @@ -214,9 +214,7 @@ function getReferenceType(model: ReferenceType, emphasis) {
if (model.typeArguments && model.typeArguments.length > 0) {
reflection.push(
`<${model.typeArguments
.map((typeArgument) =>
Handlebars.helpers.type.call(typeArgument, 'all'),
)
.map((typeArgument) => Handlebars.helpers.type.call(typeArgument))
.join(', ')}\\>`,
);
}
Expand Down
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Signatures: should compile a promise that returns a symbol' 1`] = `
"▸ \`Const\` **promiseReturningASymbol**(): [\`Promise\`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<[\`User\`](../modules.md#user)\\\\>
##### Returns
[\`Promise\`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<[\`User\`](../modules.md#user)\\\\>
"
`;

exports[`Signatures: should compile a promise that returns an object' 1`] = `
"▸ \`Const\` **promiseReturningAnObject**(): [\`Promise\`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<{ \`data\`: \`string\` ; \`id\`: \`string\` }\\\\>
##### Returns
[\`Promise\`]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise )<{ \`data\`: \`string\` ; \`id\`: \`string\` }\\\\>
"
`;
exports[`Signatures: should compile callable signature' 1`] = `
"▸ **CallableSignature**(): \`string\`
Expand Down
20 changes: 20 additions & 0 deletions packages/typedoc-plugin-markdown/test/specs/signatures.spec.ts
Expand Up @@ -55,6 +55,26 @@ describe(`Signatures:`, () => {
).toMatchSnapshot();
});

test(`should compile a promise that returns an object'`, () => {
expect(
TestApp.compileTemplate(
partial,
testApp.findReflection('promiseReturningAnObject')
.signatures[0] as SignatureReflection,
),
).toMatchSnapshot();
});

test(`should compile a promise that returns a symbol'`, () => {
expect(
TestApp.compileTemplate(
partial,
testApp.findReflection('promiseReturningASymbol')
.signatures[0] as SignatureReflection,
),
).toMatchSnapshot();
});

test(`should compile function that returns a function'`, () => {
expect(
TestApp.compileTemplate(
Expand Down
34 changes: 28 additions & 6 deletions packages/typedoc-plugin-markdown/test/stubs/src/signatures.ts
Expand Up @@ -146,13 +146,15 @@ export function commentsInReturn() {
* @param cases - Tuple of case and the result if `value` and `case` is equal
* @returns Function for which to provide the default value
*/
export const swtch = <T, R>(value: T, ...cases: [T, R][]) => (def: R) => {
for (const c of cases) {
if (c[0] === value) return c[1];
}
export const swtch =
<T, R>(value: T, ...cases: [T, R][]) =>
(def: R) => {
for (const c of cases) {
if (c[0] === value) return c[1];
}

return def;
};
return def;
};

export type _someCallback_ = (name: string, value: unknown) => void;

Expand Down Expand Up @@ -212,3 +214,23 @@ export function functionWithNestedParams(
export class ClassWithConstructor {
constructor(x: string, y: string) {}
}

export type User = {
id: string;
data: string;
};

export const promiseReturningASymbol = (): Promise<User> => {
return new Promise((resolve) => {
resolve({ id: 'id', data: 'data' });
});
};

export const promiseReturningAnObject = (): Promise<{
id: string;
data: string;
}> => {
return new Promise((resolve) => {
resolve({ id: 'id', data: 'data' });
});
};

0 comments on commit 5029a85

Please sign in to comment.