Title: TS server returns wrong type if narrowed within the same line · Issue #50002 · microsoft/TypeScript · GitHub
Open Graph Title: TS server returns wrong type if narrowed within the same line · Issue #50002 · microsoft/TypeScript
X Title: TS server returns wrong type if narrowed within the same line · Issue #50002 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms type narrowing same line 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing same line ⏯ Playground Link The playground does ...
Open Graph Description: Bug Report 🔎 Search Terms type narrowing same line 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing same lin...
X Description: Bug Report 🔎 Search Terms type narrowing same line 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing same...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50002
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS server returns wrong type if narrowed within the same line","articleBody":"# Bug Report\r\n\r\n\r\n### 🔎 Search Terms\r\n\r\ntype narrowing same line\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing same line\r\n\r\n### ⏯ Playground Link\r\nThe playground does not seem to support displaying types, but anyway ...\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/IYZwngdgxgBAZgV2gFwJYHsL3egFAI2ACcAuGEZI1CAcxgB8YAFI9AW1RAFMAeCq2gD4AlGRbtOvAG7pUAE0EwA3gCgYMQkRgBeGMADuwVMg3EA3GphRMIdABsuAOjvoaBYsIsBfFUA)\r\n\r\n### 💻 Code\r\n\r\n\r\n```ts\r\nasync function foo(bar: string | Promise\u003cstring>): Promise\u003cvoid> {\r\n bar = await bar;\r\n console.log(bar);\r\n}\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nWhen requesting the type at the location of `bar` in line 2 from TS server, the returned type should be `string` because `await bar` can only return `string`.\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe type is returned as `string | Promise\u003cstring>`:\r\n\r\n\r\n\r\nIn the next line, it works correctly:\r\n\r\n\r\n\r\nThis 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 the type at location of `baz` is requested.\r\n\r\n\r\n### Additional info\r\n\r\n[According to Tide's author](https://github.com/ananthakumaran/tide/issues/449#issuecomment-1192621907), 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.\"","author":{"url":"https://github.com/m1cm1c","@type":"Person","name":"m1cm1c"},"datePublished":"2022-07-22T14:35:50Z","url":"https://github.com/microsoft/TypeScript/issues/50002"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ed1bfee8-7220-9968-2960-1fd19814d2b2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3CE:1201C:2A83D5D:387FBAD:6B01B913 |
| html-safe-nonce | c7bef5fc7dacf99b6490e3aa87bb260d8c8bd11e6103991d2bec6c6f314303b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0NFOjEyMDFDOjJBODNENUQ6Mzg3RkJBRDo2QjAxQjkxMyIsInZpc2l0b3JfaWQiOiI3NzQ0Njg4MzAyNzA3NTU0NTc5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 06ce6e255649538565a3d32ea384c35997155b817d254e59a1150b462a86f284 |
| hovercard-subject-tag | issue:1315087912 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/50002/issue_layout |
| twitter:image | https://opengraph.githubassets.com/236a75855378b4729b3a055918e936c363de4b00a1bcc545bf1b2050a2d88068/microsoft/TypeScript/issues/50002 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/236a75855378b4729b3a055918e936c363de4b00a1bcc545bf1b2050a2d88068/microsoft/TypeScript/issues/50002 |
| og:image:alt | Bug Report 🔎 Search Terms type narrowing same line 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing same lin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | m1cm1c |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width