Title: Inferred Type Predicates doesn't narrow type if using other conditional expressions · Issue #59509 · microsoft/TypeScript · GitHub
Open Graph Title: Inferred Type Predicates doesn't narrow type if using other conditional expressions · Issue #59509 · microsoft/TypeScript
X Title: Inferred Type Predicates doesn't narrow type if using other conditional expressions · Issue #59509 · microsoft/TypeScript
Description: 🔎 Search Terms "Inferred Type Predicates" 🕗 Version & Regression Information 5.6.0-dev.20240801 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwDgpgBA8lC8UDeUDWEQC4oGdgCcBLAOwHMoBfAbgCgBjAe2LygYCMArH...
Open Graph Description: 🔎 Search Terms "Inferred Type Predicates" 🕗 Version & Regression Information 5.6.0-dev.20240801 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwDgpgBA8lC8UDeUD...
X Description: 🔎 Search Terms "Inferred Type Predicates" 🕗 Version & Regression Information 5.6.0-dev.20240801 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwD...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59509
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inferred Type Predicates doesn't narrow type if using other conditional expressions","articleBody":"### 🔎 Search Terms\n\n\"Inferred Type Predicates\"\n\n### 🕗 Version & Regression Information\n\n5.6.0-dev.20240801\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwDgpgBA8lC8UDeUDWEQC4oGdgCcBLAOwHMoBfAbgCgBjAe2LygYCMArHbACjgB8oxAK4AbUQEoA2gF0EUKSnRYoAcgCGqygBpkaDNlVstFXSPEzajZsCgAzQqOAR8EACYBGeey4A6B04uPDgIAHy4UACEiOaSVFAA9AmwsvRMLAHOrm4ATN6cOP6OWcFhEdFCYqJQAGQ1uL7KCIgaqhLxSVB8UIKx0jJpNvbFLu4AzPl+mUEh8OEhFX1Fgfilcw1N8C2a7YnJMKlAA\n\n### 💻 Code\n\n```ts\r\ntype O = { key: string };\r\nconst objs: (O | null)[] = [{ key: 'a' }, { key: 'b' }, null];\r\nconst filtered1 = objs.filter(s => s != null); // O[]\r\nconst filtered2 = objs.filter(s => s != null && s.key == 'a'); // (O | null)[]\r\nconst filtered3 = objs.filter(s => s != null).filter(s => s.key == 'a'); // O[]\r\n```\r\n\n\n### 🙁 Actual behavior\n\nThe type inferred for `filtered2` is `(O | null)[]` instead of `O[]`.\n\n### 🙂 Expected behavior\n\nI would expect `filtered2` to have the inferred type `O[]`, similar to `filtered1` and `filtered3`.\n\n### Additional information about the issue\n\n_No response_","author":{"url":"https://github.com/zyoshoka","@type":"Person","name":"zyoshoka"},"datePublished":"2024-08-02T07:18:52Z","url":"https://github.com/microsoft/TypeScript/issues/59509"}
| 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:6c3a8f67-a0a6-7c45-6d9f-2f9ee5c6105c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C39E:1AE20C:B10469:E12F4E:6B00F5AA |
| html-safe-nonce | 3d3e65399155eee56a8a6ec073827e7cf2fa3fe9ed5e3603fcbe14df4326f60a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzlFOjFBRTIwQzpCMTA0Njk6RTEyRjRFOjZCMDBGNUFBIiwidmlzaXRvcl9pZCI6IjEyMjI1MDAyMjE0MTA0MDc4NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c1887c07999c5246ebce99eecf6be56d277dc24812f7881b2b435f26ca243392 |
| hovercard-subject-tag | issue:2444259037 |
| 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/59509/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a26290a3d5c777648a4e685fe68e371f8d0d402a4965798d0d2262d1ba5647e/microsoft/TypeScript/issues/59509 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a26290a3d5c777648a4e685fe68e371f8d0d402a4965798d0d2262d1ba5647e/microsoft/TypeScript/issues/59509 |
| og:image:alt | 🔎 Search Terms "Inferred Type Predicates" 🕗 Version & Regression Information 5.6.0-dev.20240801 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwDgpgBA8lC8UDeUD... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zyoshoka |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width