diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index dafd2c6d112..91691e69fe1 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -15,7 +15,7 @@ import type { MethodParameter, } from '../../docs/.vitepress/components/api-docs/method'; import { faker } from '../../src'; -import { pathOutputDir } from './utils'; +import { formatTypescript, pathOutputDir } from './utils'; // TODO ST-DDT 2022-02-20: Actually import this/fix module import errors // import vitepressConfig from '../../docs/.vitepress/config'; @@ -245,6 +245,8 @@ function typeToText(type_: Type, short = false): string { type.indexType, short )}]`; + case 'literal': + return formatTypescript(type.toString()).replace(/;\n$/, ''); default: return type.toString(); } diff --git a/test/scripts/apidoc/signature.example.ts b/test/scripts/apidoc/signature.example.ts index 2219b072659..de1cd79a00d 100644 --- a/test/scripts/apidoc/signature.example.ts +++ b/test/scripts/apidoc/signature.example.ts @@ -115,6 +115,15 @@ export class SignatureTest { return fn('a'); } + /** + * Test with string union. + * + * @param value `'a'` or `'b'`. + */ + stringUnionParamMethod(value: 'a' | 'b'): string { + return value; + } + /** * Test with LiteralUnion. * diff --git a/test/scripts/apidoc/signature.expected.json b/test/scripts/apidoc/signature.expected.json index 5e4f913afdd..32920f7894d 100644 --- a/test/scripts/apidoc/signature.expected.json +++ b/test/scripts/apidoc/signature.expected.json @@ -39,12 +39,12 @@ "parameters": [ { "name": "value", - "type": "\"a\" | \"b\" | string", + "type": "'a' | 'b' | string", "description": "

'a' or 'b'.

\n" } ], "returns": "string", - "examples": "
faker.literalUnionParamMethod(value: \"a\" | \"b\" | string): string\n
\n
", + "examples": "
faker.literalUnionParamMethod(value: 'a' | 'b' | string): string\n
\n
", "deprecated": false, "seeAlsos": [] }, @@ -272,5 +272,21 @@ "examples": "
faker.requiredNumberParamMethod(a: number): number\n
\n
", "deprecated": false, "seeAlsos": [] + }, + "stringUnionParamMethod": { + "name": "stringUnionParamMethod", + "title": "String Union Param Method", + "description": "

Test with string union.

\n", + "parameters": [ + { + "name": "value", + "type": "'a' | 'b'", + "description": "

'a' or 'b'.

\n" + } + ], + "returns": "string", + "examples": "
faker.stringUnionParamMethod(value: 'a' | 'b'): string\n
\n
", + "deprecated": false, + "seeAlsos": [] } }