sourcegraph / javascript-typescript-langserver

JavaScript and TypeScript code intelligence through the Language Server Protocol

Home Page:https://sourcegraph.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent signatures, can't infer Promises

opened this issue · comments

Given the following example functions:

class Foobar {}
function a() {
    return new Foobar();
}

function b(text = "hello") {
    return new Promise((resolve, reject) => resolve(text));
}

async function c(text = "hello") {
    return text;
}

And checking the results of textDocument/signatureHelp and textDocument/hover:

a signatureHelp: function a(): Foobar
a hover: function a(): Foobar

b signatureHelp: function b(text?: string): any
b hover: function b(text?: string): any

c signatureHelp: function c(text?: string): {}
c hover: function c(text?: string): Promise<string>

Shouldn't the type be inferred to be function b(text?: string): Promise<string> for all 4 cases of b and c? When a function returns a primitive or a class, the types are properly inferred. But it seems like it has trouble with the types of Promises and async functions. Is this a bug in the language server?

Visual Studio Code is at least able to infer Promise<any> for function b.

I have version 2.11.1 of the language server

TypeScript can’t infer the type of the Promise from what you are passing to resolve. You need to explicitely declare the type of the Promise. There is a TSlint rule that enforces this btw.

Closing as it’s not a language server issue.

So then shouldn't it at least infer 'Promise<any>' rather than just 'any'. VSCode is able to do that.

And you haven't answered my question with respect to function 'c', either. I'm a little disappointed with your reply.

Also TSLint rules are not relevant here as in JavaScript we can't explicitly declare the type.