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'
.
faker.literalUnionParamMethod(value: \"a\" | \"b\" | string): string\n
\nfaker.literalUnionParamMethod(value: 'a' | 'b' | string): string\n
\nfaker.requiredNumberParamMethod(a: number): number\n
\nTest with string union.
\n", + "parameters": [ + { + "name": "value", + "type": "'a' | 'b'", + "description": "'a'
or 'b'
.
faker.stringUnionParamMethod(value: 'a' | 'b'): string\n
\n