diff options
| author | ST-DDT <[email protected]> | 2023-01-26 17:40:25 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-26 16:40:25 +0000 |
| commit | dcb318f4008e4600c98a794062e0d0bb061f88a9 (patch) | |
| tree | 472e224dbeab957988c61cd97dd83ef10a977dd8 /scripts | |
| parent | b86638d478fa21fafa9aaa3e247a08b479bf5a9d (diff) | |
| download | faker-dcb318f4008e4600c98a794062e0d0bb061f88a9.tar.xz faker-dcb318f4008e4600c98a794062e0d0bb061f88a9.zip | |
docs: fix unwrap literal union (#1752)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc/signature.ts | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index d34abf18..a4b384a9 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -277,20 +277,29 @@ function typeToText(type_?: Type, short = false): string { const type = type_ as SomeType; switch (type.type) { - case 'array': - return `${typeToText(type.elementType, short)}[]`; + case 'array': { + const text = typeToText(type.elementType, short); + if (text.includes('|') || text.includes('{')) { + return `Array<${text}>`; + } else { + return `${text}[]`; + } + } + case 'union': return type.types .map((t) => typeToText(t, short)) + .map((t) => (t.includes('=>') ? `(${t})` : t)) .sort() .join(' | '); + case 'reference': if (!type.typeArguments || !type.typeArguments.length) { return type.name; } else if (type.name === 'LiteralUnion') { return [ - typeToText(type.typeArguments[0]), - typeToText(type.typeArguments[1]), + typeToText(type.typeArguments[0], short), + typeToText(type.typeArguments[1], short), ].join(' | '); } else { return `${type.name}<${type.typeArguments @@ -300,13 +309,25 @@ function typeToText(type_?: Type, short = false): string { case 'reflection': return declarationTypeToText(type.declaration, short); + case 'indexedAccess': return `${typeToText(type.objectType, short)}[${typeToText( type.indexType, short )}]`; + case 'literal': return formatTypescript(type.toString()).replace(/;\n$/, ''); + + case 'typeOperator': { + const text = typeToText(type.target, short); + if (short && type.operator === 'readonly') { + return text; + } else { + return `${type.operator} ${text}`; + } + } + default: return type.toString(); } |
