1616#### Types
1717
1818- [ ` @type ` ] ( #type )
19+ - [ ` @import ` ] ( #import )
1920- [ ` @param ` ] ( #param-and-returns ) (or [ ` @arg ` ] ( #param-and-returns ) or [ ` @argument ` ] ( #param-and-returns ) )
2021- [ ` @returns ` ] ( #param-and-returns ) (or [ ` @return ` ] ( #param-and-returns ) )
2122- [ ` @typedef ` ] ( #typedef-callback-and-param )
@@ -198,7 +199,31 @@ function walk(p) {
198199}
199200```
200201
201- import types can be used in type alias declarations:
202+ 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:
203+
204+ ``` js twoslash
205+ // @filename: accounts.d.ts
206+ export const userAccount = {
207+ name: " Name" ,
208+ address: " An address" ,
209+ postalCode: " " ,
210+ country: " " ,
211+ planet: " " ,
212+ system: " " ,
213+ galaxy: " " ,
214+ universe: " " ,
215+ };
216+ // @filename: main.js
217+ // ---cut---
218+ /**
219+ * @type {typeof import("./accounts").userAccount}
220+ */
221+ var x = require (" ./accounts" ).userAccount ;
222+ ```
223+
224+ ### ` @import `
225+
226+ The ` @import ` tag can let us reference exports from other files.
202227
203228``` js twoslash
204229// @filename: types.d.ts
@@ -208,7 +233,7 @@ export type Pet = {
208233// @filename: main.js
209234// ---cut---
210235/**
211- * @typedef {import( "./types").Pet} Pet
236+ * @import {Pet} from "./types"
212237 */
213238
214239/**
@@ -218,26 +243,20 @@ var myPet;
218243myPet .name ;
219244```
220245
221- 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:
246+ These tags don't actually import files at runtime, and the symbols they bring into scope can only be used within JSDoc comments for type-checking.
222247
223248``` js twoslash
224- // @filename: accounts.d.ts
225- export const userAccount = {
226- name: " Name" ,
227- address: " An address" ,
228- postalCode: " " ,
229- country: " " ,
230- planet: " " ,
231- system: " " ,
232- galaxy: " " ,
233- universe: " " ,
234- };
249+ // @filename: dog.js
250+ export class Dog {
251+ woof () {
252+ console .log (" Woof!" );
253+ }
254+ }
255+
235256// @filename: main.js
236- // ---cut---
237- /**
238- * @type {typeof import("./accounts").userAccount}
239- */
240- var x = require (" ./accounts" ).userAccount ;
257+ /** @import { Dog } from "./dog.js" */
258+
259+ const d = new Dog (); // error!
241260```
242261
243262### ` @param ` and ` @returns `
0 commit comments