Title: Filter with "something is smallerType" don't work as negative · Issue #58996 · microsoft/TypeScript · GitHub
Open Graph Title: Filter with "something is smallerType" don't work as negative · Issue #58996 · microsoft/TypeScript
X Title: Filter with "something is smallerType" don't work as negative · Issue #58996 · microsoft/TypeScript
Description: 🔎 Search Terms filter is type narrow negative 🕗 Version & Regression Information This starts on version 5.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAggdgSwLYEMA2UC8UDeAoKKAIwCcIVgALALimBIFcIAaPAXwG48...
Open Graph Description: 🔎 Search Terms filter is type narrow negative 🕗 Version & Regression Information This starts on version 5.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAggdgSwLYEM...
X Description: 🔎 Search Terms filter is type narrow negative 🕗 Version & Regression Information This starts on version 5.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAggdgSw...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/58996
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Filter with \"something is smallerType\" don't work as negative","articleBody":"### 🔎 Search Terms\n\nfilter is type narrow negative\n\n### 🕗 Version & Regression Information\n\n- This starts on version 5.5\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAggdgSwLYEMA2UC8UDeAoKKAIwCcIVgALALimBIFcIAaPAXwG489RIoAlAPYBjANZZcBYmQo0oAM3QBnFuy49w0AMqCkEKgjgBzCfGTooAHwEjR6+QzjDgCQXCgIlZ1GgAUS3X1KQyNaHT0DYwBKWgCI4OMPJVhEH0lCMmAGEnc4oJCAOlJyKnZuYTclYDoIKoBGMMDIk2x8QmLZWnomVjZyyurgWuAAJkb4kIk26RK5RTQVXvUKuCq6YKUASSUAeXFsAG0h+uYaqpGAXQL5BDQhkl9qzAA+JO90R6iorgB6H8IAYQAHoAfhS5jQBwu-VWgw22wA6iQ3C0oEdhnVTsdRlcbncIA8nq8AISed5+YBfX7-QHAsG+clWGxiKJQvBAA\n\n### 💻 Code\n\n```ts\r\ntype Animal = {\r\n breath: true,\r\n};\r\n\r\ntype Rock = {\r\n breath: false,\r\n};\r\n\r\ntype Something = Animal | Rock;\r\n\r\nfunction isAnimal(something: Something): something is Animal {\r\n return something.breath\r\n}\r\n\r\nconst test1: Something = {\r\n breath: true,\r\n}\r\n\r\nconst test2: Something = {\r\n breath: false,\r\n};\r\n\r\nconst thisIsOk = [test1, test2].filter(t => isAnimal(t));\r\n// ^? Animal[]\r\n\r\nconst thisIsWrong = [test1, test2].filter(t => !isAnimal(t));\r\n// ^? (Animal | Rock)[]\r\n\r\n```\r\n\n\n### 🙁 Actual behavior\n\n```ts\r\n\r\nconst thisIsOk = [test1, test2].filter(t => isAnimal(t));\r\n// ^? Animal[]\r\n\r\nconst thisIsWrong = [test1, test2].filter(t => !isAnimal(t));\r\n// ^? (Animal | Rock)[]\r\n\r\n```\n\n### 🙂 Expected behavior\n\n```ts\r\n\r\nconst thisIsOk = [test1, test2].filter(t => isAnimal(t));\r\n// ^? Animal[]\r\n\r\nconst thisIsShouldBe = [test1, test2].filter(t => !isAnimal(t));\r\n// ^? Rock[]\r\n\r\n```\n\n### Additional information about the issue\n\nFiltering is working only if \"positive\", but if the \"is\" is used as a negative then it don't type narrow.","author":{"url":"https://github.com/Noriller","@type":"Person","name":"Noriller"},"datePublished":"2024-06-24T18:59:16Z","url":"https://github.com/microsoft/TypeScript/issues/58996"}
| 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:5562ece6-ee70-da1f-f29e-b6fcb463b292 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C872:2454CC:9E4E1F:CAB8E1:6B00F28A |
| html-safe-nonce | 6708d7e08b74e3fd53cc834f2be1e7facf3e4b7eebcb02269892dbf5094f49eb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODcyOjI0NTRDQzo5RTRFMUY6Q0FCOEUxOjZCMDBGMjhBIiwidmlzaXRvcl9pZCI6IjE0Mjg4MzIyNjcwODE0MTMyNTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b74bfa66a36d804a24d90b38c4fdafe36048998f19698a2f21aadcfa4bc3c8ec |
| hovercard-subject-tag | issue:2370898808 |
| 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/58996/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed12f9b530497ec8ce315f060fdf0bd1b0eca672dc945bc1c4533637f3b44252/microsoft/TypeScript/issues/58996 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed12f9b530497ec8ce315f060fdf0bd1b0eca672dc945bc1c4533637f3b44252/microsoft/TypeScript/issues/58996 |
| og:image:alt | 🔎 Search Terms filter is type narrow negative 🕗 Version & Regression Information This starts on version 5.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAggdgSwLYEM... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Noriller |
| 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