ts-migrate icon indicating copy to clipboard operation
ts-migrate copied to clipboard

JSDoc plugin is not working properly

Open just-jeb opened this issue 1 year ago • 4 comments

I'm trying to migrate a JS project (that contains JSDoc annotations) to TS project. So far I've been able to come to a point where all my files are TS, everything compiles and the bundle is produced.

However, when I try to run JSDoc plugin and hopefully convert all the JSDoc annotations to proper TS types it doesn't really work. This is what I do (and the output):

npx ts-migrate migrate --plugin jsdoc packages/my-project
TypeScript version: 4.9.4
Initialized tsserver project in 81ms.
Start...
[jsdoc] Plugin 1 of 1. Start...
[jsdoc] Finished in 7ms.
Finished in 7ms, for 1 plugin(s).
Writing 0 updated file(s)...
Wrote 0 updated file(s) in 1ms.

This is my tsconfig.json (located at packages/my-project):

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "ESNext",
    "allowJs": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "rootDir": "src",
    "outDir": "dist/esm",
    "noImplicitAny": false,
    "declarationDir": "dist/types",
    "declaration": true
  },
  "compileOnSave": false,
  "include": [
    "src"
  ]
}

And this is an example for one of the JSDoc annotations located in one of the files (say packages/my-project/src/example.ts):

/**
 * @param {Promise<{entryType: string}>[]} entries
 * @param {Promise} aPromise
 * @param {import('./entries/result').Result} result
 */
export default function foo(
  entries,
  aPromise,
  results,
) {
// implementation here
}

I would expect this JSDoc to be transformed into typed signature. Did I get that wrong? Isn't it what the JSDoc plugin supposed to do? Or am I just using it the wrong way?

P.S. I also tried to use older version (as it seemed to solve the issue earlier), but it didn't help.

just-jeb avatar Dec 26 '22 15:12 just-jeb

did you solve it @just-jeb ?

kotmatpockuh avatar Dec 28 '23 13:12 kotmatpockuh

Nope I gave up 😅.

just-jeb avatar Dec 28 '23 14:12 just-jeb

Nope I gave up 😅.

por favor señor, I got a solution for you right here. (at least the one that worked for us)

We had to downgrade our typescript version in the project to 4.7.2 (which is the one used for this package) So just run

npm install -D [email protected]
or
yarn add -D [email protected]

And then try to run your migration.js file or the extremely well documented CLI.

Hope it works for you, best wishes and happy new year.

Laberbear avatar Jan 18 '24 14:01 Laberbear

@Laberbear absolutely fantastic, this worked and saved me so much time, thank you for sharing this workaround!

connorjclark avatar Jun 12 '24 23:06 connorjclark