ananthakumaran / tide

Tide - TypeScript Interactive Development Environment for Emacs
GNU General Public License v3.0
1.46k stars 109 forks source link

Wrong type displayed if narrowed within the same line #449

Closed m1cm1c closed 2 years ago

m1cm1c commented 2 years ago

Relevant Version Numbers

Steps to Reproduce the Bug

Paste the following code into a TS buffer:

async function foo(bar: string | Promise<string>): Promise<void> {
  bar = await bar;
  console.log(bar);
}

Expected Behavior

When placing point on bar in line 2, the displayed type should be string because await bar can only return string.

Actual Behavior

The type is displayed as string | Promise<string>: Screenshot_20220722_160549

In the next line, it works correctly: Screenshot_20220722_160608

This only happens if the variable on the left pre-exists, i.e. let baz = await bar; or const baz = await bar; does not exhibit this behavior when point is placed on baz.

ananthakumaran commented 2 years ago

Check the debugging section. Tide sends the cursor location to the tsserver and doesn't know much. Any bug related to semantics should be reported to typescript repo

m1cm1c commented 2 years ago

@ananthakumaran Thank you. Will report it there.