neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.06k stars 68 forks source link

Strange issue with JSDoc being replaced by `any` #369

Closed rschristian closed 2 years ago

rschristian commented 2 years ago

I've ran into a really odd issue in which a promise's resolved value gets replaced with any under a number of circumstances, but only with coc-tsserver. I cannot reproduce this behavior in any other editor.

I tried to cut this down as much as I could, apologies if this is still a bit heavy. Removing anything else pretty much means it cannot be reproduced.

In the example below, foo is shown to have a type of any, however, doing any of the following steps corrects it:

Calling Foo() from a plain async function or top-level doesn't result in this issue. It seems limited to this library's method.

TS Server Log pastebin

Project

src/index.js

import { Router } from "worktop";

new Router().add("GET", "/:foo", async (_req, context) => {
    const foo = await Foo(String(context.params.foo));

    return console.log(foo);
});

/**
 * @param {string} stringParam
 * @returns {Promise<{ foo: number, bar: [] }>}
 */
async function Foo(stringParam) {
    return {
        foo: 0,
        bar: []
    };
}

jsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowJs": true,
    "checkJs": true
  },
  "include": [
    "src/index.js"
  ]
}

package.json

{
"name": "tmp",
"private": true,
"dependencies": {
"typescript": "^4.6.4",
"worktop": "^0.8.0-next.13"
}
}
chemzqm commented 2 years ago

In the example below, foo is shown to have a type of any

Screen Shot 2022-05-06 at 12 59 17

Can't reproduce, works as expected for me.

rschristian commented 2 years ago

Well the instant-close feels a bit premature, any ideas what could lead to this? Definitely isn't working correctly for me.

temp

chemzqm commented 2 years ago

Maybe you have turned off "typescript.suggest.jsdoc.generateReturns". Or maybe you need wait for a while, tsserver needs some time to parse jsdoc

rschristian commented 2 years ago

Hm, not sure if you just skimmed over the issue without reading or what, but I did say that there are a number of things I could do to have the type "magically" show up. Like the 4th item, swapping out String(context.params.foo) with a static string ("foo").

temp

There's no reason why that should have an effect, but for some reason it does. The type CAN resolve (and does so quickly enough, I'm using the same isolated test case provided here), but in that specific code block, it doesn't. It's really weird.

I don't think it's possible to be an issue in user code/config.

chemzqm commented 2 years ago

You have to wait for sometime, it's issue with tsserver. You should send report to typescript team.

rschristian commented 2 years ago

The type doesn't change over time. I get any even if I leave it for 3-4 minutes.

You should send report to typescript team.

I can't reproduce the issue outside of coc, so the issue doesn't seem to be with typescript. Works just fine in CodeSandbox, for example.

chemzqm commented 2 years ago

From log of your tsserver

Info 90   [06:25:06.286] response:
    {"seq":0,"type":"response","command":"completionEntryDetails","request_seq":10,"success":true,"body":[{"name":"foo","kindModifiers":"","kind":"const","displayParts":[{"text":"const","kind":"keyword"},{"text":" ","kind":"space"},{"text":"foo","kind":"localName"},{"text":":","kind":"punctuation"},{"text":" ","kind":"space"},{"text":"any","kind":"keyword"}],"documentation":[],"tags":[]}]}

it's what it returned, I got same response first time and it gives me correct type after some seconds.

chemzqm commented 2 years ago

It happens on latest VSCode as well

Screen Shot 2022-05-06 at 14 42 28
rschristian commented 2 years ago

Hmm, weird. I don't know if it's just my method of get syntax hints (I don't have hover hints, just when I go to use the value) but nothing ever changes, the hint is completely static.

Odd that you can reproduce in VSCode, I think I tried for a half hour to get CodeSandbox to reproduce but never once did. Fair enough then, sorry to bring it up here.