Skip to content
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

feat: Add functionality to export doc strings on struct fields and enum variants #228

Closed
wants to merge 15 commits into from

Conversation

timephy
Copy link
Contributor

@timephy timephy commented Feb 9, 2024

This is an "extension" of #187 and tries to also export doc strings not only on "full types" but also on the fields/variants of structs/enums.

Example

#[derive(TS)]
#[ts(export_to = "tests-out/docs/")]
struct A {
    /// Doc of field
    ///
    /// Testing
    name: String,
}

is exported as

export interface A {
    /**
     * Doc of field
     *
     * Testing
     */
    name: string,
}

Comments

JSDocs are only shows when starting in a new line

image image

This of course interferes with the "format" feature and because of the requirement to start in a new line, all tests I guess.

JSDocs are not applicable to unions (enums)

See microsoft/tsdoc#164

This might depend on whether the enum is tagged internally/externally, etc.

@escritorio-gustavo
Copy link
Contributor

escritorio-gustavo commented Feb 9, 2024

Hey @timephy! It seems this PR contains duplicates of the commits in #187. I think it would be a good idea to sync your main branch to this repo's and then create a new branch and PR to avoid this issue

@escritorio-gustavo
Copy link
Contributor

escritorio-gustavo commented Feb 9, 2024

Notes:

  • Generated TS now creates types instead of interfaces
export interface A {
    /**
     * Doc of field
     *
     * Testing
     */
    name: string,
}

Should be

export type A = {
    /**
     * Doc of field
     *
     * Testing
     */
    name: string,
}

JSDocs are only shows when starting in a new line

This of course interferes with the "format" feature and because of the requirement to start in a new line, all tests I guess.

Great observation! This likely means that in case the format feature is off we will have to either:

  • avoid generating field docs, as they will not be rendered
  • emit newline characters before each documented field (The newline could be added to the start of the doc string, should be easy enough)

JSDocs are not applicable to unions (enums)

This might depend on whether the enum is tagged internally/externally, etc.

Sadly there is no reasonable way to document enum variants, regardless of tagging, we should keep this to struct fields (which, on the bright side, will affect fields inside an enum's struct variant)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants