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.

RFC: Specify that doc comments are allowed on simple union types

See original GitHub issue

Hello,

I can’t find any documentation on adding tsdocs to a typescript string literal type. I was wondering if the following is possible:

type InputType = 
/** the TSDoc doesn't work for num1, but I'd like it to */
| 'num1'
/** the TSDoc doesn't work for num2, but I'd also like it to */
| 'num2'

export const test = (...input: InputType[]) => {
    return input
}

// I'd like to get the TSDoc from 'num1' string literal to show up
// when inputting it into the `tac` function but it does not currently show
test('num1')

I’m not 100% tied to using string literal types, so if there is another way to do this with enums, etc., I’d love to learn 😄

If the above is not currently possible, I’d love to work to add it to tsdoc (with some guidance 😄).

Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:71
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
octogonzcommented, Apr 24, 2020

@Gerrit0 my thinking to restrict this feature to a very special pattern that is commonly used like an enum. We could give it a name like “union enum”.

For example, these would be union enums:

/**
 * A standard system color.
 */
export type Color = 
  /**
   * The color `#ff0000`
   */
  'red' | // do we care whether "|" is before/after the comment? Not really
  /**
   * The color `#00ff00`
   */
  'green' 
  /**
   * The color `#0000ff`
   */
  | 'blue';

/**
 * A binary digit.
 */
export type Bit = /** zero */  0  |  /** one*/ 1;

But it’s optional. For example, maybe a documentation tool only treats a type as an “union enum” if at least one of the members has a /** */ comment.

And it would NOT apply to any other generalized expressions, not even this sort of thing:

// NOT a union enum:
type Mammal = Cat | Dog | Horse;

For the most part, such a feature would be a feature request for your particular documentation tool. If TSDoc “supports” this feature, its role is merely to:

  • specify that it’s “standard” to put doc comments on these subexpressions
  • provide a declaration reference notation for referring to them
10reactions
christianalfonicommented, Feb 12, 2020

Hi there, I have the same thing. I am using String Literal types to define classnames and would love to populate with some more information.

So basically:

type TClassnames = 
	| 'bg-color-red-500'
    | 'bg-color-red-600'

I would love to populate the docs on the right side of the intellisense:

Screenshot 2020-02-12 at 07 31 36

This is how we can document with properties:

Screenshot 2020-02-12 at 10 10 59

Which would be amazing to have on string literals

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP RFC: Union Types 2.0
Supporting union types in the language allows us to move more type information from phpdoc into function signatures, with the usual advantages ...
Read more >
Request for Comments Summary RFC Numbers 3400-3499
This is a status report on these RFCs. This memo provides information for the Internet community. It does not specify an Internet standard...
Read more >
RFC 6020: YANG - A Data Modeling Language for the ...
1. Modules and Submodules A module contains three types of statements: module-header statements, revision statements, and definition statements. · 2. Data ...
Read more >
Final draft ETSI ES 201 873-10 V4.2.2 (2011-04)
Part 10: TTCN-3 Documentation Comment Specification ... In the case of record, set and union types, module parameters, constants and templates the ...
Read more >
PHP 8.0: Union Types
Union types does not allow redundant class types. However, it is important to note that this only applies to a few special special...
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