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

"About Types" page based on @type #180

Closed
wants to merge 6 commits into from
Closed

"About Types" page based on @type #180

wants to merge 6 commits into from

Conversation

samthor
Copy link

@samthor samthor commented Aug 15, 2017

Resolves #154.

@hegemonic

@samthor
Copy link
Author

samthor commented Aug 31, 2017

Friendly ping.

@hegemonic

Copy link
Contributor

@hegemonic hegemonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the lengthy delay in reviewing this pull request. I'll make an effort to get it merged quickly once you've addressed my comments.

@@ -0,0 +1,261 @@
---
title: Types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to do two more things so that this page actually shows up on the website:

  1. Add the page to an appropriate place in data/toc.json.
  2. Run gulp to rebuild the HTML files for the website.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

are specified with the [`@type` tag][type-tag], the [`@param` tag][param-tag], and many others.

[type-tag]: tags-type.html
[param-tag]: tags-param.html.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing period.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

[Google Closure Compiler type expression][closure], as well as several other formats that are
specific to JSDoc.

If JSDoc determines that a type expression is invalid, it will display an error and stop running.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your fault, but this paragraph is no longer accurate. It should say something more like:

If JSDoc determines that a type expression is invalid, it will display an error message. To force JSDoc to stop running when a type expression is invalid, use the --pedantic option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<td>
<p>
This means a value can have one of several types, with the entire list of types enclosed in
parentheses and separated by <code>|</code>. The parentheses are required for Closure Compiler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this accurate? I thought Closure Compiler supported type unions without parentheses, even though that behavior isn't documented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc says that they're required, but we then ignore that rule most other places. So you're right, I'll make it clear that they're optional by saying Closure "suggests" them.

</code></pre>
{% endexample %}

{% example "An object called 'myObj' with properties 'a' (a number), 'b' (a string) and 'c' (any type)." %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comma after "(a string)"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</p>
<p>
For objects that have a known set of properties, you can use Closure Compiler's syntax for
documenting record types. You can document each property individually, which enables you to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/You/As an alternative, you/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</td>
<td>
<p>
Document a callback using the <a href="tags-callback.html">@callback</a> tag. The syntax is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enclose tag name in <code>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<td>
<p>
Document a callback using the <a href="tags-callback.html">@callback</a> tag. The syntax is
identical to the @typedef tag, except that a callback's type is always "function."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enclose tag name in <code>, and change "function." to <code>function</code>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

may contain, or the type of value returned by a function. You can also include type expressions with
many other JSDoc tags, such as the [@param tag][param-tag].
The `@type` tag allows you to provide a type expression identifying the type of value that a symbol
may contain, or inline to indicate that a symbol is of a specific type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this confusing. Please rewrite along these lines: "...may contain. For function parameters, you can also use an inline @type tag to identify a parameter's type."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text works with my casting example, below, hence why it might be confusing. I've taken the suggestion though and made it about function parameters.

@@ -297,3 +57,12 @@ var FOO = 1;
var FOO = 1;
```
{% endexample %}

To indicate that a variable is of a certain type, you can cast it with @type. The surrounding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a Closure Compiler thing that has nothing to do with JSDoc, so please remove this example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So: we have a bunch of examples that refer to Closure Compiler all around the site, and I strongly think that casting is a very important use of @type for Closure. With that in mind, I've updated the example to make it clear it's just for Closure—what do you think now?

To be clear, I'm very happy to be overruled, just stating my case a bit more clearly.

@samthor samthor mentioned this pull request Sep 18, 2017
@hegemonic hegemonic deleted the branch jsdoc:master October 19, 2023 04:44
@hegemonic hegemonic closed this Oct 19, 2023
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