question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[playground] No parsing of TypeScript type information?

See original GitHub issue

I’m experimenting with the TSDoc Playground and I can’t seem to make it parse TypeScript type information. Here’s a sample:

/**
 * Returns the average of two numbers.
 *
 * @remarks
 * This method is part of the {@link core-library#Statistics | Statistics subsystem}.
 *
 * @param x - The first input number
 * @param y - The second input number
 * @returns The arithmetic mean of `x` and `y`
 *
 * @beta
 */
function getAverage(x: number, y: number) {
    return (x + y) / 2.0;
}

As you can see, the ParamBlocks in the AST don’t include any type annotations for x and y.

  - ParamBlock
    - BlockTag
      * BlockTag="@param"
    * Spacing=" "
    * ParamBlock_ParameterName="x"
    * Spacing=" "
    * ParamBlock_Hyphen="-"
    * Spacing=" "
    - Section
      - Paragraph
        - PlainText
          * PlainText="The first input number"
        - SoftBreak
          * SoftBreak="\n"
  - ParamBlock
    - BlockTag
      * BlockTag="@param"
    * Spacing=" "
    * ParamBlock_ParameterName="y"
    * Spacing=" "
    * ParamBlock_Hyphen="-"
    * Spacing=" "
    - Section
      - Paragraph
        - PlainText
          * PlainText="The second input number"
        - SoftBreak
          * SoftBreak="\n"

Thoughts?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
liamrosscommented, Oct 25, 2018

I understand that perhaps parsing the actual TypeScript code is outside of the scope of what TSDoc is trying to accomplish, but it was definitely something I hoped would be included since I first noticed this project gaining some traction.

In the README it says:

The majority of the standard JSDoc tags are preoccupied with providing type annotations for plain JavaScript, which is an irrelevant concern for a strongly-typed language such as TypeScript.

However, the fact that my documentation will have zero indication of the type of a parameter means that this could never serve as a replacement for JSDoc for me personally. If I write a library in TypeScript and it is consumed by a JavaScript application, I would like for there to be typings in the documentation, and not require that people are relying on IDE tooling or digging into the package to find types.

The first thing that drew me to this was the idea of it parsing types from the code to save the redundant declarations in the documentation.

Is there a reason why this is excluded from this project? It seems like a gap to not include typing in documentation personally.

0reactions
octogonzcommented, Mar 18, 2019

@fastfedo encountered the same confusion in https://github.com/Microsoft/tsdoc/issues/152#issuecomment-474026798 . He gave a couple suggestions:

Two things might have helped me here:

  1. Documentation examples in/linked from the README that show usage with different TypeScript constructs (interface, type, class, enum, etc).

  2. A note on the TSDoc playground that it’s not actually parsing TypeScript, or that only the first comment is being parsed, as you stated above. So the playground is not a place to explore how more complex types would be documented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TS Playground - An online editor for exploring TypeScript and ...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Read more >
Typescript doesn't figure out the generic - Stack Overflow
I'm starting to learn about typescript and I tried to make an parser combinator library, at first types and generics where easy, but...
Read more >
Linting with Type Information | typescript-eslint
You're using an outdated version of @typescript-eslint/parser . Update to the latest version to see a more informative version of this error message,...
Read more >
Typescript's type system - From solving puzzles to ... - YouTube
Typescript has gained a lot of traction with majority of javascript frameworks adopting it and gaining the power of static types.
Read more >
Pragmatic uses of Typescript type system 04
TS playground ↗. From the point of view of Javascript, b variable will still contain a number, but Typescript compiler now knows, that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found