Skip to content

Commit 778f64d

Browse files
committed
docs: fix bad Promise usage
1 parent 5801c79 commit 778f64d

File tree

5 files changed

+59
-24
lines changed

5 files changed

+59
-24
lines changed

scripts/apidoc/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export async function generate(): Promise<void> {
2222
// Useful for manually analyzing the content
2323
await app.generateJson(project, pathOutputJson);
2424

25-
const pages = await Promise.all([
25+
const pages = [
2626
...(await processFakerClasses(project)),
2727
...(await processModules(project)).sort((a, b) =>
2828
a.text.localeCompare(b.text)
2929
),
3030
await processFakerRandomizer(project),
31-
processFakerUtilities(project),
32-
]);
31+
await processFakerUtilities(project),
32+
];
3333
await writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
3434
writeApiDiffIndex(
3535
Object.fromEntries(pages.map(({ text, diff }) => [text, diff]))

scripts/apidoc/signature.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ async function typeToText(type_?: Type, short = false): Promise<string> {
226226
].join(' | ');
227227
}
228228

229-
return `${type.name}<${type.typeArguments
230-
.map(async (t) => await typeToText(t, short))
231-
.join(', ')}>`;
229+
return `${type.name}<${(
230+
await Promise.all(type.typeArguments.map((t) => typeToText(t, short)))
231+
).join(', ')}>`;
232232

233233
case 'reflection':
234234
return declarationTypeToText(type.declaration, short);

test/scripts/apidoc/__snapshots__/signature.spec.ts.snap

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports[`signature > analyzeSignature() > complexArrayParameter 1`] = `
4343
"returns": "T",
4444
"seeAlsos": [],
4545
"since": "",
46-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L358",
46+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L367",
4747
"throws": undefined,
4848
}
4949
`;
@@ -93,6 +93,7 @@ exports[`signature > analyzeSignature() > expected and actual methods are equal
9393
"optionsInterfaceParamMethodWithDefaults",
9494
"optionsParamMethod",
9595
"optionsTypeParamMethodWithDefaults",
96+
"recordParamMethod",
9697
"requiredNumberParamMethod",
9798
"stringUnionParamMethod",
9899
]
@@ -198,7 +199,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecated 1`] = `
198199
"test.apidoc.methodWithExample()",
199200
],
200201
"since": "",
201-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L278",
202+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L287",
202203
"throws": undefined,
203204
}
204205
`;
@@ -250,7 +251,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecatedOption 1`] = `
250251
"returns": "number",
251252
"seeAlsos": [],
252253
"since": "",
253-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L299",
254+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L308",
254255
"throws": undefined,
255256
}
256257
`;
@@ -268,7 +269,7 @@ exports[`signature > analyzeSignature() > methodWithExample 1`] = `
268269
"returns": "number",
269270
"seeAlsos": [],
270271
"since": "",
271-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L267",
272+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L276",
272273
"throws": undefined,
273274
}
274275
`;
@@ -288,7 +289,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = `
288289
"test.apidoc.methodWithDeprecated()",
289290
],
290291
"since": "",
291-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L326",
292+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L335",
292293
"throws": undefined,
293294
}
294295
`;
@@ -308,7 +309,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic
308309
"test.apidoc.methodWithDeprecated() with parameter <code>bar</code> and <code>baz</code>.",
309310
],
310311
"since": "",
311-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L336",
312+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
312313
"throws": undefined,
313314
}
314315
`;
@@ -325,7 +326,7 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = `
325326
"returns": "number",
326327
"seeAlsos": [],
327328
"since": "1.0.0",
328-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
329+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L354",
329330
"throws": undefined,
330331
}
331332
`;
@@ -342,7 +343,7 @@ exports[`signature > analyzeSignature() > methodWithThrows 1`] = `
342343
"returns": "number",
343344
"seeAlsos": [],
344345
"since": "",
345-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L287",
346+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L296",
346347
"throws": "a Faker error",
347348
}
348349
`;
@@ -491,7 +492,7 @@ It also has a more complex description.</p>
491492
"returns": "number",
492493
"seeAlsos": [],
493494
"since": "",
494-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L217",
495+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L226",
495496
"throws": undefined,
496497
}
497498
`;
@@ -530,15 +531,15 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault
530531
"returns": "number",
531532
"seeAlsos": [],
532533
"since": "",
533-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L253",
534+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L262",
534535
"throws": undefined,
535536
}
536537
`;
537538
538539
exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
539540
{
540541
"deprecated": undefined,
541-
"description": "<p>Test with a function parameters.</p>
542+
"description": "<p>Test with an options parameter.</p>
542543
",
543544
"examples": "<div class=\\"language-ts\\"><button title=\\"Copy Code\\" class=\\"copy\\"></button><span class=\\"lang\\">ts</span><pre v-pre class=\\"shiki material-theme-palenight\\"><code><span class=\\"line\\"><span style=\\"color:#82AAFF\\">optionsParamMethod</span><span style=\\"color:#BABED8\\">(options: </span><span style=\\"color:#89DDFF\\">{</span></span>
544545
<span class=\\"line\\"><span style=\\"color:#BABED8\\"> </span><span style=\\"color:#F07178\\">a</span><span style=\\"color:#89DDFF\\">:</span><span style=\\"color:#BABED8\\"> number</span><span style=\\"color:#89DDFF\\">,</span></span>
@@ -552,7 +553,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
552553
"parameters": [
553554
{
554555
"default": undefined,
555-
"description": "<p>The function parameter.</p>
556+
"description": "<p>The options parameter.</p>
556557
",
557558
"name": "options",
558559
"type": "{ ... }",
@@ -596,7 +597,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
596597
"returns": "number",
597598
"seeAlsos": [],
598599
"since": "",
599-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L187",
600+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L196",
600601
"throws": undefined,
601602
}
602603
`;
@@ -635,7 +636,32 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`]
635636
"returns": "number",
636637
"seeAlsos": [],
637638
"since": "",
638-
"sourcePath": "test/scripts/apidoc/signature.example.ts#L235",
639+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L244",
640+
"throws": undefined,
641+
}
642+
`;
643+
644+
exports[`signature > analyzeSignature() > recordParamMethod 1`] = `
645+
{
646+
"deprecated": undefined,
647+
"description": "<p>Test with a Record parameter.</p>
648+
",
649+
"examples": "<div class=\\"language-ts\\"><button title=\\"Copy Code\\" class=\\"copy\\"></button><span class=\\"lang\\">ts</span><pre v-pre class=\\"shiki material-theme-palenight\\"><code><span class=\\"line\\"><span style=\\"color:#82AAFF\\">recordParamMethod</span><span style=\\"color:#BABED8\\">(object: Record</span><span style=\\"color:#89DDFF\\">&lt;</span><span style=\\"color:#BABED8\\">string</span><span style=\\"color:#89DDFF\\">,</span><span style=\\"color:#BABED8\\"> number</span><span style=\\"color:#89DDFF\\">&gt;</span><span style=\\"color:#BABED8\\">): number</span></span></code></pre>
650+
</div>",
651+
"name": "recordParamMethod",
652+
"parameters": [
653+
{
654+
"default": undefined,
655+
"description": "<p>The Record parameter.</p>
656+
",
657+
"name": "object",
658+
"type": "Record<string, number>",
659+
},
660+
],
661+
"returns": "number",
662+
"seeAlsos": [],
663+
"since": "",
664+
"sourcePath": "test/scripts/apidoc/signature.example.ts#L182",
639665
"throws": undefined,
640666
}
641667
`;

test/scripts/apidoc/signature.debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { loadExampleMethods } from './utils';
1111
const methods = loadExampleMethods();
1212

1313
initMarkdownRenderer()
14-
.then(() => {
14+
.then(async () => {
1515
for (const [name, method] of Object.entries(methods)) {
1616
console.log('Analyzing:', name);
17-
const result = analyzeSignature(method, '', method.name);
17+
const result = await analyzeSignature(method, '', method.name);
1818
console.log('Result:', result);
1919
}
2020
})

test/scripts/apidoc/signature.example.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,18 @@ export class SignatureTest {
175175
}
176176

177177
/**
178-
* Test with a function parameters.
178+
* Test with a Record parameter.
179179
*
180-
* @param options The function parameter.
180+
* @param object The Record parameter.
181+
*/
182+
recordParamMethod(object: Record<string, number>): number {
183+
return object.a;
184+
}
185+
186+
/**
187+
* Test with an options parameter.
188+
*
189+
* @param options The options parameter.
181190
* @param options.a The number parameter.
182191
* @param options.b The string parameter.
183192
* @param options.c The boolean parameter.

0 commit comments

Comments
 (0)