futurGH/ts-to-jsdoc

Type is not being imported

Closed this issue · 10 comments

The output in jsdoc has not the type import.

desired file "example.ts":

import { ParamType } from "./example2";

function someFunction(param: ParamType) {}

file "example2.ts" where the type is located:

export type ParamType = string;

Output JS:

/**
 * @param {ParamType} param
 * @returns {void}
 */
function someFunction(param) { }
export {};

Use proper import type - TypeScript removes unused imports.

In my Typescript files I usually import with just import. Is there a way to check if the import is a type?

Is there a way to check if the import is a type?

Didn't try it myself, but this seems to be exactly what you ask for, check out this: https://typescript-eslint.io/rules/consistent-type-imports/

What I meant is if there is a way to create a check if the import is a type in this library(ts-to-jsdoc) to then use it like it is right now.
Example:
input

import { ParamType } from "./example2";

function someFunction(param: ParamType) {}

output

/**
 * @typedef {import('./example2.js').ParamType} ParamType
 */

/**
 * @param {ParamType} param
 * @returns {void}
 */
function someFunction(param) { }
export {};

So you can keep your code where everything is confusing and conflated together? import type exists for a reason and you better clean up your code.

Why the library could not handle that? Not all the code uses import type?

You should be using import type to import types, but I think it should be possible for ts-to-jsdoc to detect when an import is only used in a type position. Will look into that when I get a chance.

I'm trying to add this feat. But I didn't find a function to get the type of the import yet

Already implemented, just need to write a test or two today and I'll publish ;)

Fixed in 2.0.0!