Title: Type guards in Array.prototype.filter · Issue #7657 · microsoft/TypeScript · GitHub
Open Graph Title: Type guards in Array.prototype.filter · Issue #7657 · microsoft/TypeScript
X Title: Type guards in Array.prototype.filter · Issue #7657 · microsoft/TypeScript
Description: TypeScript Version: nightly (1.9.0-dev.20160323) Code let numbers: number[] = [1, '2', 3, '4'].filter(x => typeof x !== 'string'); declare function isNumber(arg: any): arg is number; let numbers2: number[] = [1, '2', 3, '4'].filter(isNum...
Open Graph Description: TypeScript Version: nightly (1.9.0-dev.20160323) Code let numbers: number[] = [1, '2', 3, '4'].filter(x => typeof x !== 'string'); declare function isNumber(arg: any): arg is number; let numbers2: ...
X Description: TypeScript Version: nightly (1.9.0-dev.20160323) Code let numbers: number[] = [1, '2', 3, '4'].filter(x => typeof x !== 'string'); declare function isNumber(arg: any): ar...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7657
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type guards in Array.prototype.filter","articleBody":"**TypeScript Version:** \n\nnightly (1.9.0-dev.20160323)\n\n**Code**\n\n``` ts\nlet numbers: number[] =\n [1, '2', 3, '4'].filter(x => typeof x !== 'string');\n\ndeclare function isNumber(arg: any): arg is number;\nlet numbers2: number[] = [1, '2', 3, '4'].filter(isNumber);\n```\n\n[Playground](http://www.typescriptlang.org/Playground#src=let%20numbers%3A%20number%5B%5D%20%3D%0A%20%20%20%20%5B1%2C%20'2'%2C%203%2C%20'4'%5D.filter%28x%20%3D%3E%20typeof%20x%20!%3D%3D%20'string'%29%3B%0A%0Adeclare%20function%20isNumber%28arg%3A%20any%29%3A%20arg%20is%20number%3B%0Alet%20numbers2%3A%20number%5B%5D%20%3D%20%5B1%2C%20'2'%2C%203%2C%20'4'%5D.filter%28isNumber%29%3B)\n\n**Expected behavior:**\n.filter with a type guard returns an array of the specified type. This would be especially useful with `--strictNullChecks`, so we could do something like `foo.map(maybeReturnsNull).filter(x => x != null)....`\n\n**Actual behavior:** \n.filter returns an array of the same type, and the two `let`s above are errors.\n","author":{"url":"https://github.com/calebegg","@type":"Person","name":"calebegg"},"datePublished":"2016-03-23T17:07:24Z","url":"https://github.com/microsoft/TypeScript/issues/7657"}
| 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:0c306c3f-bfae-5936-fbeb-1d6d488ee8c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EDE0:14F601:113C3C4:16087C3:6B0104A9 |
| html-safe-nonce | 04effbffc0b322c183716e1f9d536407530d6614bfe0bf9cd25927e7be9d64d7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREUwOjE0RjYwMToxMTNDM0M0OjE2MDg3QzM6NkIwMTA0QTkiLCJ2aXNpdG9yX2lkIjoiODAwNTE2Mzc1NDA4MzkxMDgyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 24c7c39a921ccf9767da2f0b683c78ab574b83e9f9bfd0aabc26ce1905094aab |
| hovercard-subject-tag | issue:143021695 |
| 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/7657/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e4fefe88239d094ce42c0f88167fdc8c981140b7f87c5c84a094e4f327522fa7/microsoft/TypeScript/issues/7657 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e4fefe88239d094ce42c0f88167fdc8c981140b7f87c5c84a094e4f327522fa7/microsoft/TypeScript/issues/7657 |
| og:image:alt | TypeScript Version: nightly (1.9.0-dev.20160323) Code let numbers: number[] = [1, '2', 3, '4'].filter(x => typeof x !== 'string'); declare function isNumber(arg: any): arg is number; let numbers2: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | calebegg |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width