-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TS server returns wrong type if narrowed within the same line #50002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking βSign up for GitHubβ, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
But at that point the type of the variable is still |
On a second thought, I think it makes most sense to show the declared type (as it currently does) when assigning. After all, that's the type that determines compatibility. |
Okay, this is a fair point. TS server actually seems to behave consistently when setting this as the goal. At least I wasn't able to find any inconsistencies with this. Closing the issue. Thank you for this comment. |
Bug Report
π Search Terms
type narrowing same line
π Version & Regression Information
β― Playground Link
The playground does not seem to support displaying types, but anyway ...
Playground link with relevant code
π» Code
π Expected behavior
When requesting the type at the location of
bar
in line 2 from TS server, the returned type should bestring
becauseawait bar
can only returnstring
.π Actual behavior
The type is returned as

string | Promise<string>
:In the next line, it works correctly:

This only happens if the variable on the left pre-exists, i.e.
let baz = await bar;
orconst baz = await bar;
does not exhibit this behavior when the type at location ofbaz
is requested.Additional info
According to Tide's author, the types displayed in the minibuffer are the types returned by TS server: "Tide sends the cursor location to the tsserver and doesn't know much."
The text was updated successfully, but these errors were encountered: