Skip to Content
The Public InterfaceSeptember 12, 2026

The Public Interface

February 12, 2025

JSDoc @import Tag

A better way to write types with JSDoc comments.

By Ross Robinojavascript / jsdoc

It’s nice to have type safety in .js files, you can configure TypeScript to also check these files in your tsconfig.json with these two compiler options.

I use this frequently in configuration files or in node scripts that I don’t want to compile before running in CI.

When you need to use a type for something in a JavaScript file, you can write them in JSDoc /** */ comments with a @type tags. Most frequently this is needed when you can’t infer the type, for example the parameters of a function.

I used to struggle to remember the syntax for importing types from other modules.

TypeScript 5.5 added support for importing types with the @import tag. This aligns with ESM import syntax and to me, it is much easier to remember. You can also reuse the type in multiple places if needed.

If you are publishing a library to npm, it might seem easier to write it in JavaScript and publish the source code directly. Unfortunately, TypeScript will not pick up the types from your JSDoc comments when your package is imported from node_modules by default. If you want users to have types with your package you will still need to generate .d.ts files and publish them alongside your .js.

Since either option requires some kind of build step, I think it’s easier to just write .ts files and use the TypeScript tsc compiler for most packages. This ensures you have accurate .d.ts files that are generated from your .ts files.…

Continue reading

In brief

Document Svelte Projects with HTML and JSDoc Comments

Use documentation comments to thoroughly document your Svelte code.

Documenting code with JSDoc comments not only simplifies the lives of maintainers and consumers, but it also offers several advantageous alternatives to regular comments. JSDoc comments enable hints to appear in convenient locations, making code documentation even more valuable. In this article, we will explore a few effective methods to document Svelte code using HTML and JSDoc comments. Entire Svelte components can be documented with HTML comments that include @component.

August 3, 2023