microsoft / microsoft/TypeScript

IntelliSense for generic Promise function shows truncated return type

Open
#39,517 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TS Template added by @mjbvz

TypeScript Version: 4.0.0-dev.20200702

Search Terms

  • hover / quick info
  • truncation

  • VSCode Version: 1.46.1 (user setup)
  • OS Version: Windows_NT x64 10.0.18363

Steps to Reproduce:

App.ts:

import { Repro} from "./Repro";

function test()
{
    Repro.repro<number>("test");
}

Repro.ts:

export namespace Repro
{
    export interface Arg { argName: string, argValue: any }

 // export async function repro<T>(AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijkl: string, ...methodArgs: Arg[]): Promise<T> // Working
    export async function repro<T>(AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklX: string, ...methodArgs: Arg[]): Promise<T> // Broken
    {
        return (new Promise<T>(null));
    }
}

Problem:

In App.ts, hover over the .repro function. The IntelliSense shows repro as having a return type of Promise<...>. This is incorrect: it should be Promise<number>.

Now, in Repro.ts edit the repro function by remove the trailing X in the first parameter name. Return to App.ts and note that the IntelliSense for repro is now correct (the function return type is shown as Promise<number>).

While at first glance this may appear to be an edge case due to the long identifier name, it is not. I ran into this problem with "normal length" parameters, but the example above was the simplest repro I could find. Here's the signature of the function where I originally saw the problem:

export async function postForkAsync<T>(destinationInstance: string, methodName: string, methodVersion: number, errorTemplate: string = null, resultTimeoutInMs: number = -1, ...methodArgs: PostMethodArg[]): Promise<T>

Does this issue occur when all extensions are disabled?: Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the hover behavior using App.ts and Repro.ts, including the long generic function parameter and the version with the trailing X. Trace the IntelliSense return-type display to determine why it shows Promise<...> instead of Promise; done means the reproduced hover shows the complete generic return type without relying on parameter-name length.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.