futurGH / ts-to-jsdoc

Transpile TypeScript code to fully compatible JavaScript + JSDoc comments.
MIT License
181 stars 17 forks source link

Type is not being imported #38

Closed OuthBack closed 9 months ago

OuthBack commented 9 months ago

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 {};
kungfooman commented 9 months ago

Use proper import type - TypeScript removes unused imports.

OuthBack commented 9 months ago

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

kungfooman commented 9 months ago

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/

OuthBack commented 9 months ago

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 {};
kungfooman commented 9 months ago

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.

OuthBack commented 9 months ago

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

futurGH commented 9 months ago

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.

OuthBack commented 9 months ago

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

futurGH commented 9 months ago

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

futurGH commented 9 months ago

Fixed in 2.0.0!