Title: Arrow functions cannot be used as user-defined type guards · Issue #5951 · microsoft/TypeScript · GitHub
Open Graph Title: Arrow functions cannot be used as user-defined type guards · Issue #5951 · microsoft/TypeScript
X Title: Arrow functions cannot be used as user-defined type guards · Issue #5951 · microsoft/TypeScript
Description: User defined type guards work perfectly well for classic function statements, as in the release notes: interface Animal {name: string; } interface Cat extends Animal { meow(); } function isCat(a: Animal): a is Cat { return a.name === 'ki...
Open Graph Description: User defined type guards work perfectly well for classic function statements, as in the release notes: interface Animal {name: string; } interface Cat extends Animal { meow(); } function isCat(a: A...
X Description: User defined type guards work perfectly well for classic function statements, as in the release notes: interface Animal {name: string; } interface Cat extends Animal { meow(); } function isCat(a: A...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5951
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Arrow functions cannot be used as user-defined type guards","articleBody":"User defined type guards work perfectly well for classic function statements, as in the release notes:\n\n``` typescript\ninterface Animal {name: string; }\ninterface Cat extends Animal { meow(); }\n\nfunction isCat(a: Animal): a is Cat {\n return a.name === 'kitty';\n}\n```\n\nHowever, it appears that the arrow function equivalent isn't acceptable:\n\n``` typescript\n// Doesn't compile\nvar isReallyCat: (a: Animal) => a is Cat = (cat) => cat.name === 'kitty';\n```\n\nThis gives \"Type '(cat: Animal) => boolean' is not assignable to type '(a: Animal) => a is Cat'. Signature '(cat: Animal): boolean' must have a type predicate\". I'm not clear how I would give that arrow function a 'type predicate', beyond what's already included here.\n\nIs there a good reason for this? I can't seem to find it documented anywhere.\n","author":{"url":"https://github.com/pimterry","@type":"Person","name":"pimterry"},"datePublished":"2015-12-06T02:44:03Z","url":"https://github.com/microsoft/TypeScript/issues/5951"}
| 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:6d9dd567-031e-ec59-bda2-a5b176d67d08 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DAFE:229B2E:C2939E:1026391:6B00F280 |
| html-safe-nonce | bcde5b5d500392317abc9abb42d2fceb0e1f986c469e0d8af69d18fc8e627eb4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQUZFOjIyOUIyRTpDMjkzOUU6MTAyNjM5MTo2QjAwRjI4MCIsInZpc2l0b3JfaWQiOiI4NzMyMzIyNTQzNTkzMTI0NDgwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f7a1b31882d09f64c7143be32576456107b1fbb0512e45995ff943e99196ab48 |
| hovercard-subject-tag | issue:120603353 |
| 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/5951/issue_layout |
| twitter:image | https://opengraph.githubassets.com/00d634dc879a11028ca6ea492afd178264c3251f8d8ed28fe1100986b023dcd1/microsoft/TypeScript/issues/5951 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/00d634dc879a11028ca6ea492afd178264c3251f8d8ed28fe1100986b023dcd1/microsoft/TypeScript/issues/5951 |
| og:image:alt | User defined type guards work perfectly well for classic function statements, as in the release notes: interface Animal {name: string; } interface Cat extends Animal { meow(); } function isCat(a: A... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pimterry |
| 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