Title: Control flow analysis for dependent parameters only works when checking against literals · Issue #55766 · microsoft/TypeScript · GitHub
Open Graph Title: Control flow analysis for dependent parameters only works when checking against literals · Issue #55766 · microsoft/TypeScript
X Title: Control flow analysis for dependent parameters only works when checking against literals · Issue #55766 · microsoft/TypeScript
Description: 🔎 Search Terms narrow, parameters, typeof 🕗 Version & Regression Information It never worked for typeof / asserts checks since the feature introduction in #47190; it's been mentioned here: #47190 (comment) ⏯ Playground Link https://www.t...
Open Graph Description: 🔎 Search Terms narrow, parameters, typeof 🕗 Version & Regression Information It never worked for typeof / asserts checks since the feature introduction in #47190; it's been mentioned here: #47190 (...
X Description: 🔎 Search Terms narrow, parameters, typeof 🕗 Version & Regression Information It never worked for typeof / asserts checks since the feature introduction in #47190; it's been mentioned here: ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/55766
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Control flow analysis for dependent parameters only works when checking against literals","articleBody":"### 🔎 Search Terms\r\n\r\nnarrow, parameters, typeof\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nIt never worked for `typeof` / `asserts` checks since the feature introduction in https://github.com/microsoft/TypeScript/pull/47190; it's been mentioned here:\r\n\r\nhttps://github.com/microsoft/TypeScript/pull/47190#issuecomment-1041216006\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play?#code/MYewdgzgLgBAZmAMgSygUwE4EMA2AuGACgDpSsMBzCAgbQAMs6AaGMAVwFsAjTAXRgA+Mel2YxoGZGAq8AlDAC8APhgA3EMgAmiolhZd5ymAG8AUDBjI4uxQoUwARFgfyzFi6EggcaYjhAUhAYA3ObuAPTh7tHuAHoA-GEAvqYppp7Q8GAAghAQmFAEJGSU1MIMYuzcfILloiwSUjKGKupaOoR6MAaKKm6W1oTIENmdsq5hHuAQ3r7+gSGTMJExMQnJqenTsAgAKgCeAA5oIHBFpMTkVLRVPBgstzVCNI3SDVCS0nK9ahra9p19C0TGErEQoEcTtYsLZ7A5HhgXCDohlZn4AkFZKFoitVnFEhYUmk4GwwMAoMhwJYRoRVLgCKSANZgEAAdzAsgIdJw1JgFWRMAwaCgbAwYBgHzYaFCKSAA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nconst fnLiteral: (...args: [`a`, number] | [`b`, string]) => void = (a, b) => {\r\n if (a === \"a\") {\r\n console.log(b);\r\n // ^? number\r\n }\r\n}\r\n\r\nconst fnAssert: (...args: [`a`, number] | [`b`, string]) => void = (a, b) => {\r\n if (isA(a)) {\r\n console.log(b);\r\n // ^? number | string\r\n }\r\n}\r\nconst fnTypeof: (...args: [number, number] | [string, string]) => void = (a, b) => {\r\n if (typeof a === \"number\") {\r\n console.log(b);\r\n // ^? number | string\r\n }\r\n}\r\n\r\nfunction isA(val: unknown): val is `a` {\r\n return true;\r\n}\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nBoth `fnAssert` and `fnTypeof` are unable to get TS to recognize `b` as its narrowed type (`number`). Only if `a` is checked against a literal does the narrowing works.\r\n\r\n### 🙂 Expected behavior\r\n\r\nThe `b` parameter should be narrowed to `number`.\r\n\r\n### Additional information about the issue\r\n\r\n_No response_","author":{"url":"https://github.com/arcanis","@type":"Person","name":"arcanis"},"datePublished":"2023-09-17T11:43:55Z","url":"https://github.com/microsoft/TypeScript/issues/55766"}
| 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:8926d8b4-52aa-fa2b-3f7f-571dd9216be5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAD6:329C7F:1D1470:281760:6B0466AD |
| html-safe-nonce | 6924355cb150e9002cb2b0534db27cc51384bdf42a1c42ea4614a1bd285cbd01 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUQ2OjMyOUM3RjoxRDE0NzA6MjgxNzYwOjZCMDQ2NkFEIiwidmlzaXRvcl9pZCI6IjcyMDk4ODE1MDkwNDA1MTQ3MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 52bdc543443164985a6b9287925eb9cf84a04e19a7a9354ff34d3cb11f67365f |
| hovercard-subject-tag | issue:1899755704 |
| 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/55766/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ea74d2eb9c12c2076d50fee5e6bb36e2458ce0c8764820cb11be301aaf4ff09a/microsoft/TypeScript/issues/55766 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ea74d2eb9c12c2076d50fee5e6bb36e2458ce0c8764820cb11be301aaf4ff09a/microsoft/TypeScript/issues/55766 |
| og:image:alt | 🔎 Search Terms narrow, parameters, typeof 🕗 Version & Regression Information It never worked for typeof / asserts checks since the feature introduction in #47190; it's been mentioned here: #47190 (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arcanis |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width