Title: instanceof does not respect inherited `Symbol.hasInstance` · Issue #56536 · microsoft/TypeScript · GitHub
Open Graph Title: instanceof does not respect inherited `Symbol.hasInstance` · Issue #56536 · microsoft/TypeScript
X Title: instanceof does not respect inherited `Symbol.hasInstance` · Issue #56536 · microsoft/TypeScript
Description: 🔎 Search Terms hasinstance, instanceof, 2359, TS2359 🕗 Version & Regression Information I was unable to test this on prior versions because this is recent functionality introduced in #55052 ⏯ Playground Link https://www.typescriptlang.or...
Open Graph Description: 🔎 Search Terms hasinstance, instanceof, 2359, TS2359 🕗 Version & Regression Information I was unable to test this on prior versions because this is recent functionality introduced in #55052 ⏯ Playg...
X Description: 🔎 Search Terms hasinstance, instanceof, 2359, TS2359 🕗 Version & Regression Information I was unable to test this on prior versions because this is recent functionality introduced in #55052 ⏯ P...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/56536
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"instanceof does not respect inherited `Symbol.hasInstance`","articleBody":"### 🔎 Search Terms\r\n\r\nhasinstance, instanceof, 2359, TS2359\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- I was unable to test this on prior versions because this is recent functionality introduced in #55052\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play?declaration=false&target=9&module=7&ts=5.4.0-dev.20231124#code/C4TwDgpgBAEghgZwJIDsHDigxhA8gMygF4oBvAKCigG0BlEAWwCMB7AGwDoALRVdTHAF0AFAA8AXAFcUAaxQsA7igCU4qK3YRM5AL7lyAegNQWM8vmlZgASxYooDEHwzY8+MVNnylAGihZxeGQ0FxwCZQoqACcIYEko+1EoaxCBCBZCLF19I3Uo0wgUc0sbOwcnVNcCVGAIKIQIK1sUD2k5RRQ-AKDnNIIoADITJgArRuAIyigYuISoJJT+Vwz-bMNjJnyZQuLsUvtHXqr8AHFCuussAB4AYSgIUVqUABMEWF5KsPwAPlavDq64huk2isXiiWSn3SmV0QA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype HasInstanceOf = {\r\n [Symbol.hasInstance](x:unknown): boolean\r\n}\r\n\r\n// ok\r\nfunction myInstanceOf(x:unknown, c:HasInstanceOf){\r\n return x instanceof c\r\n}\r\n\r\n// broken\r\nfunction myInstanceOfIntersection(x:unknown, c:HasInstanceOf & object){\r\n return x instanceof c\r\n}\r\n\r\n// broken\r\nfunction myInstanceOfGeneric\u003cC extends HasInstanceOf>(x:unknown, c:C){\r\n return x instanceof c\r\n}\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe second and third examples give error TS2359\r\n> The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method.\r\n\r\nIn all cases, the right-hand side *is* an object type with a `Symbol.hasInstance` method.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI expect all three examples to typecheck.\r\n\r\n### Additional information about the issue\r\n\r\n_No response_","author":{"url":"https://github.com/rotu","@type":"Person","name":"rotu"},"datePublished":"2023-11-25T04:35:39Z","url":"https://github.com/microsoft/TypeScript/issues/56536"}
| 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:560c0f4a-8fef-299d-00b9-9481d804054e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8052:361639:26F53E1:340C1B7:6B01B08C |
| html-safe-nonce | 2e4b26a40d9cdeab34463fe713abb112bc7b42e0d5759c66908ca705a81bfc8d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDUyOjM2MTYzOToyNkY1M0UxOjM0MEMxQjc6NkIwMUIwOEMiLCJ2aXNpdG9yX2lkIjoiODkyNTUxMjY5MzcxMzA1NTg4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dde4f375aba46c0d0ae1bc74923f843691727f59b335f6d89afd69947aec3fb9 |
| hovercard-subject-tag | issue:2010469930 |
| 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/56536/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e0e63efd14402bccdcfbf0de6815f989096d1d54f3e9b244a0b6507ed1af4b81/microsoft/TypeScript/issues/56536 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e0e63efd14402bccdcfbf0de6815f989096d1d54f3e9b244a0b6507ed1af4b81/microsoft/TypeScript/issues/56536 |
| og:image:alt | 🔎 Search Terms hasinstance, instanceof, 2359, TS2359 🕗 Version & Regression Information I was unable to test this on prior versions because this is recent functionality introduced in #55052 ⏯ Playg... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rotu |
| 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