Skip to content

Object unions generate invalid comments #60

@Secreto31126

Description

@Secreto31126

I was testing the app with a proyect, which has tons of complex types with documented properties, and it seems like unions break the comments, generating invalid syntax.

Minimal reproduction:

type Type = {
        /** Hi */
        b: 1;
} | {
        c: string;
};

New text:

/**
 * @typedef {{
 *         /** Hi */
 *         b: 1;
 * } | {
 *         c: string;
 * }} Type
 */
type Type = {
        /** Hi */
        b: 1;
} | {
        c: string;
};

Worth pointing out, this also breaks with optional (?), such as:

type Type = {
        a?: {
                /** Hi */
                b: 1;
        };
};
/**
 * @typedef {Object} Type
 * @property {{		/** Hi */		b: 1;	}} [a] 
 */
type Type = {
	a?: {
		/** Hi */
		b: 1;
	};
};

I doubt the tsconfig changes anything, but just in case:

{
    "include": ["index.ts"],
    "compilerOptions": {
        "target": "ESNext",
        "module": "Preserve",
        "moduleResolution": "Bundler",
        "declaration": true,
        "declarationMap": true,
        "emitDeclarationOnly": true,
        "isolatedModules": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "skipLibCheck": true
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions