Title: `instanceof` does not narrow when the class is intersected with `&` · Issue #50844 · microsoft/TypeScript · GitHub
Open Graph Title: `instanceof` does not narrow when the class is intersected with `&` · Issue #50844 · microsoft/TypeScript
X Title: `instanceof` does not narrow when the class is intersected with `&` · Issue #50844 · microsoft/TypeScript
Description: 🔎 Search Terms instanceof, narrow. 🕗 Version & Regression Information This is a crash This is the behavior in every version I tried (from 3.8.3 to to 4.9.0-dev.20220919), and I reviewed the FAQ for entries about it. ⏯ Playground Link Pla...
Open Graph Description: 🔎 Search Terms instanceof, narrow. 🕗 Version & Regression Information This is a crash This is the behavior in every version I tried (from 3.8.3 to to 4.9.0-dev.20220919), and I reviewed the FAQ for...
X Description: 🔎 Search Terms instanceof, narrow. 🕗 Version & Regression Information This is a crash This is the behavior in every version I tried (from 3.8.3 to to 4.9.0-dev.20220919), and I reviewed the FAQ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50844
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`instanceof` does not narrow when the class is intersected with `&`","articleBody":"### 🔎 Search Terms\r\n\r\n`instanceof`, `narrow`.\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is a crash\r\n- This is the behavior in every version I tried (from `3.8.3` to to `4.9.0-dev.20220919`), and I reviewed the FAQ for entries about it.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=99&noPropertyAccessFromIndexSignature=true&exactOptionalPropertyTypes=true#code/JYOwLgpgTgZghgYwgAgJIgM5jiJB5EFAbwChlkB7QgCgEoAuZANwuABMSBfE0SWRFOiw4kAFQDuFZKXJhJdRi3ZcSCKlmShhuFAF5pnZHAxpM2HQRQAfU9rGSSq9WGQBhADbGMlgOpQqAObI+kSGxtLIhOLICrbm+ITIhgBkETAUFIxgUACuKNzAMDFa8SglIhAURR5evv4gAbTSZJpmFQB0VBB0yAD0vcgACv4ADtBgAJ7IAORd08hsFBAmIBQuEAAewFgANMgARhAIcDkYKAAG5TrnmitrkXBQ-uIQbAsU4iAqTmZunhjeQgAJWAAQAFi4QmETERIhBorEhKVLHt0plkNk8kkeEVqFckK07JVqv9ARAQeCwE0ZITSp0aE1+kNRuMprNCPNNtswCYcG9Lm1rrcHk8Pq93p8VEA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ninterface InstanceOne {\r\n one(): void\r\n}\r\ninterface InstanceTwo {\r\n two(): void\r\n}\r\nconst instance = {} as InstanceOne | InstanceTwo\r\n\r\nconst ClassOneWrong = {} as { new (): InstanceOne } & { foo: true }\r\nif (instance instanceof ClassOneWrong) {\r\n instance.one() // Property 'one' does not exist, because `instance` is not narrowed down\r\n}\r\n\r\nconst ClassOneRight = {} as { new (): InstanceOne, foo: true }\r\nif (instance instanceof ClassOneRight) {\r\n instance.one() // Property 'one' exists and `instance` is narrowed down\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n`instanceof` does not narrow down the left side when the right side is a type using `&`.\r\n\r\n### 🙂 Expected behavior\r\n\r\nIt should narrow it down to `InstanceOne`, and `instance.one()` should pass.","author":{"url":"https://github.com/ehmicky","@type":"Person","name":"ehmicky"},"datePublished":"2022-09-19T12:55:32Z","url":"https://github.com/microsoft/TypeScript/issues/50844"}
| 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:1ea6a6b2-fd9f-6c75-03a1-f7c3fc37d076 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91C4:F7C4C:2803410:359A728:6B01BB41 |
| html-safe-nonce | af4dfd05ae786f1c70d8bd6b9c8d54ffd834b5965aeaf6f7c63c946ac51a5e91 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUM0OkY3QzRDOjI4MDM0MTA6MzU5QTcyODo2QjAxQkI0MSIsInZpc2l0b3JfaWQiOiI2NjM1NzExNTY3NzM4NTUxMTA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c809f7e20c296ee0b8409ceb8289c801a58805460ed547bca2bbd73185106c14 |
| hovercard-subject-tag | issue:1377914915 |
| 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/50844/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b8b0874264355989c6c5139d02056281ce3e8330b2e458519e840b07d997c283/microsoft/TypeScript/issues/50844 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b8b0874264355989c6c5139d02056281ce3e8330b2e458519e840b07d997c283/microsoft/TypeScript/issues/50844 |
| og:image:alt | 🔎 Search Terms instanceof, narrow. 🕗 Version & Regression Information This is a crash This is the behavior in every version I tried (from 3.8.3 to to 4.9.0-dev.20220919), and I reviewed the FAQ for... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ehmicky |
| 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