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

Document the JSDoc @import tag #3170

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions packages/documentation/copy/en/javascript/JSDoc Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Note:
#### Types

- [`@type`](#type)
- [`@import`](#import)
- [`@param`](#param-and-returns) (or [`@arg`](#param-and-returns) or [`@argument`](#param-and-returns))
- [`@returns`](#param-and-returns) (or [`@return`](#param-and-returns))
- [`@typedef`](#typedef-callback-and-param)
Expand Down Expand Up @@ -198,26 +199,6 @@ function walk(p) {
}
```

import types can be used in type alias declarations:

```js twoslash
// @filename: types.d.ts
export type Pet = {
name: string,
};
// @filename: main.js
// ---cut---
/**
* @typedef {import("./types").Pet} Pet
*/

/**
* @type {Pet}
*/
var myPet;
myPet.name;
```

import types can be used to get the type of a value from a module if you don't know the type, or if it has a large type that is annoying to type:

```js twoslash
Expand All @@ -240,6 +221,28 @@ export const userAccount = {
var x = require("./accounts").userAccount;
```

### `@import`

`@import` can be used for type-only imports:
remcohaszing marked this conversation as resolved.
Show resolved Hide resolved

```js twoslash
// @filename: types.d.ts
export type Pet = {
name: string,
};
// @filename: main.js
// ---cut---
/**
* @import {Pet} from "./types"
*/

/**
* @type {Pet}
*/
var myPet;
myPet.name;
```

remcohaszing marked this conversation as resolved.
Show resolved Hide resolved
### `@param` and `@returns`

`@param` uses the same type syntax as `@type`, but adds a parameter name.
Expand Down