Title: Type inference ignores explicit type annotation · Issue #55330 · microsoft/TypeScript · GitHub
Open Graph Title: Type inference ignores explicit type annotation · Issue #55330 · microsoft/TypeScript
X Title: Type inference ignores explicit type annotation · Issue #55330 · microsoft/TypeScript
Description: 🔎 Search Terms type inference explicit type narrowing type annotation 🕗 Version & Regression Information TS version 5.1.6 ⏯ Playground Link https://www.typescriptlang.org/play?#code/IYZwngdgxgBAZgV2gFwJYHsI1JKBBEEVAcwgFsBTCZACggC4YIEyAjC...
Open Graph Description: 🔎 Search Terms type inference explicit type narrowing type annotation 🕗 Version & Regression Information TS version 5.1.6 ⏯ Playground Link https://www.typescriptlang.org/play?#code/IYZwngdgxgBAZgV...
X Description: 🔎 Search Terms type inference explicit type narrowing type annotation 🕗 Version & Regression Information TS version 5.1.6 ⏯ Playground Link https://www.typescriptlang.org/play?#code/IYZwngdgxgB...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/55330
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type inference ignores explicit type annotation","articleBody":"### 🔎 Search Terms\n\ntype inference\r\nexplicit type\r\nnarrowing\r\ntype annotation\n\n### 🕗 Version & Regression Information\n\nTS version 5.1.6\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play?#code/IYZwngdgxgBAZgV2gFwJYHsI1JKBBEEVAcwgFsBTCZACggC4YIEyAjCgJwEpGAFD9GVQgKAHmZtOAPhgBvAFAwlMADYVkMZBQAeyRiGQdUEYjAA+TBCpUwAvJesBueYuUQKAdxj9BwijRoOChB0FQA3Ci47GQVlOM0dDXsAchDKBN1k53jlIJDw-yQAEwo4YwoirlclAF8q6uwPYFQNdy8fIREAvNCIqNsZEWQAFVRKdARaHoKAGhgARgAGZcWuLmcG1DgYGi1dO1t7Zmso2JyYIOQEDixFhpqXOMvrrD3kADo1E2QAC2caoA\n\n### 💻 Code\n\n```ts\r\nasync function asyncAssignment(n: number): Promise\u003cnumber> {\r\n let text: string | null = null;\r\n\r\n new Promise((resolve) => {\r\n text = 'some text';\r\n resolve(undefined)\r\n })\r\n\r\n await new Promise((resolve) => setTimeout(resolve, 10000));\r\n\r\n if (text === null) {\r\n return 0\r\n }\r\n\r\n return text.length;\r\n}\r\n```\r\n\n\n### 🙁 Actual behavior\n\nTypescript narrows `text` type to `null` and not to `string | null`\n\n### 🙂 Expected behavior\n\nExpecting to have `string | null` type for `text` before explicit type narrowing (`if (text === null)`) and `string` type after explicit type narrowing","author":{"url":"https://github.com/belyakov-am","@type":"Person","name":"belyakov-am"},"datePublished":"2023-08-10T14:44:04Z","url":"https://github.com/microsoft/TypeScript/issues/55330"}
| 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:c3f9f6d2-61d0-7cd5-98c4-1ccf1ac06ea0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9910:2E3FEE:2B9D5C8:373AE97:6B01AB70 |
| html-safe-nonce | 3713db58278a13d644f7ed06e5f0d05b8e0e6347770f8f84c35adf2bcb3fa767 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTEwOjJFM0ZFRToyQjlENUM4OjM3M0FFOTc6NkIwMUFCNzAiLCJ2aXNpdG9yX2lkIjoiNjQyMjY0NjYzNjg0NTA1MDczNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6d6fa3f7769b3ceb132f66f4a40a739023f26115e4b9f67c26cdecc99100b3c8 |
| hovercard-subject-tag | issue:1845337263 |
| 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/55330/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f849f253a2e894e67c46252c79ae6e001ccae53f85cce94c0114693d57e0dd4f/microsoft/TypeScript/issues/55330 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f849f253a2e894e67c46252c79ae6e001ccae53f85cce94c0114693d57e0dd4f/microsoft/TypeScript/issues/55330 |
| og:image:alt | 🔎 Search Terms type inference explicit type narrowing type annotation 🕗 Version & Regression Information TS version 5.1.6 ⏯ Playground Link https://www.typescriptlang.org/play?#code/IYZwngdgxgBAZgV... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | belyakov-am |
| 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