Skip to content

Commit

Permalink
fix: long union type
Browse files Browse the repository at this point in the history
issue: #181
  • Loading branch information
hosseinmd committed Oct 5, 2023
1 parent 2f5de4f commit 4f9ba4c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/utils.ts
Expand Up @@ -108,9 +108,12 @@ async function formatType(type: string, options?: Options): Promise<string> {
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*\]$/, "");
Expand Down
19 changes: 18 additions & 1 deletion tests/__snapshots__/typeScript.test.ts.snap
Expand Up @@ -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
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/typeScript.test.ts
Expand Up @@ -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();
});

0 comments on commit 4f9ba4c

Please sign in to comment.