Skip to content

Comments get truncated in generated declaration files #22037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Stevenic opened this issue Feb 19, 2018 · 3 comments
Closed

Comments get truncated in generated declaration files #22037

Stevenic opened this issue Feb 19, 2018 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files

Comments

@Stevenic
Copy link

TypeScript Version:
2.6.2

Search Terms:
truncate comments

Code
The following code when compiled with "declaration": true:

/**
 * @module botbuilder-choices
 */
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.  
 * Licensed under the MIT License.
 */

const breakingChars = " \n\r~`!@#$%^&*()-+={}|[]\\:\";'<>?,./";

export interface Token {
    start: number;
    end: number;
    text: string;
    normalized: string;
}

export type TokenizerFunction = (text: string, locale?: string) => Token[];

Expected behavior:
Should generate a .d.ts file that looks like this:

/**
 * @module botbuilder-choices
 */
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
export interface Token {
    start: number;
    end: number;
    text: string;
    normalized: string;
}
export declare type TokenizerFunction = (text: string, locale?: string) => Token[];

Actual behavior:
But instead it generates this with the comments stripped off:

export interface Token {
    start: number;
    end: number;
    text: string;
    normalized: string;
}
export declare type TokenizerFunction = (text: string, locale?: string) => Token[];

If I simply change the code to this then it works fine:

/**
 * @module botbuilder-choices
 */
/**
 * Copyright (c) Microsoft Corporation. All rights reserved.  
 * Licensed under the MIT License.
 */

export interface Token {
    start: number;
    end: number;
    text: string;
    normalized: string;
}

const breakingChars = " \n\r~`!@#$%^&*()-+={}|[]\\:\";'<>?,./";

export type TokenizerFunction = (text: string, locale?: string) => Token[];

The compiler will truncate the leading comments if the first construct in the file isn't exported. The same thing happens if you import a type from a module but that type isn't referenced by something you export.

The leading comments are needed by a TypeDoc plugin we're using and every time this happens what ever is in the file gets dropped from our documentation. I've been working around the issue by manually checking the generated .d.ts files for months and now other devs on our team are starting to accidentally break our docs.

I really need this fixed...

@Stevenic
Copy link
Author

Stevenic commented Mar 8, 2018

bump... Any word on this?

@mhegazy mhegazy added Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files labels Mar 8, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2018

should be fixed by #21930..

For now, if you want to preserve the comment add a ! at the beginning. Comments at the beginning of the file with ! are considered copy-write comments and are always emitted..

@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 8, 2018
@Stevenic
Copy link
Author

Thanks... Everything is ok right now as we've just made sure that we properly order our imports. I was more worried about the long term need to constantly check the output. I'll close this for now,

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files
Projects
None yet
Development

No branches or pull requests

3 participants