diff --git a/src/utils.ts b/src/utils.ts index 459e174..6666bf1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -108,9 +108,12 @@ async function formatType(type: string, options?: Options): Promise { filepath: "file.ts", }); pretty = pretty.slice(TYPE_START.length); - pretty = pretty.replace(/^\s*/g, ""); - pretty = pretty.replace(/[;\n]*$/g, ""); - pretty = pretty.trim(); + + pretty = pretty + .replace(/^\s*/g, "") + .replace(/[;\n]*$/g, "") + .replace(/^\|/g, "") + .trim(); if (rest) { pretty = "..." + pretty.replace(/\[\s*\]$/, ""); diff --git a/tests/__snapshots__/typeScript.test.ts.snap b/tests/__snapshots__/typeScript.test.ts.snap index b1ec7eb..a27e604 100644 --- a/tests/__snapshots__/typeScript.test.ts.snap +++ b/tests/__snapshots__/typeScript.test.ts.snap @@ -49,9 +49,26 @@ export let User; " `; +exports[`Long type Union types 1`] = ` +"/** + * Gets a configuration object assembled from environment variables and .env + * configuration files. + * + * @memberof Config + * @function getEnvConfig + * @returns {Config.SomeConfiguration + * | Config.SomeOtherConfiguration + * | Config.AnotherConfiguration + * | Config.YetAnotherConfiguration} + * The environment configuration + */ +export default () => configurator.config; +" +`; + exports[`Union types 1`] = ` "/** - * @typedef {| { foo: string } + * @typedef {{ foo: string } * | { bar: string; manyMoreLongArguments: object } * | { baz: string }} Foo */ diff --git a/tests/typeScript.test.ts b/tests/typeScript.test.ts index 3c4144b..08df00a 100644 --- a/tests/typeScript.test.ts +++ b/tests/typeScript.test.ts @@ -175,3 +175,18 @@ test("Union types", async () => { expect(result).toMatchSnapshot(); }); + +test("Long type Union types", async () => { + const result = await subject(` + /** + * Gets a configuration object assembled from environment variables and .env configuration files. + * + * @memberof Config + * @function getEnvConfig + * @returns {Config.SomeConfiguration | Config.SomeOtherConfiguration | Config.AnotherConfiguration | Config.YetAnotherConfiguration } The environment configuration + */ + export default () => configurator.config; +`); + + expect(result).toMatchSnapshot(); +});