Title: Type narrowing not working as expected · Issue #11245 · microsoft/TypeScript · GitHub
Open Graph Title: Type narrowing not working as expected · Issue #11245 · microsoft/TypeScript
X Title: Type narrowing not working as expected · Issue #11245 · microsoft/TypeScript
Description: TypeScript Version: 2.0.2 RC Code This code fails: function f1(arg: string[]) {} function f2(arg: ArrayLike
Open Graph Description: TypeScript Version: 2.0.2 RC Code This code fails: function f1(arg: string[]) {} function f2(arg: ArrayLike
X Description: TypeScript Version: 2.0.2 RC Code This code fails: function f1(arg: string[]) {} function f2(arg: ArrayLike<string> | string[]) { if (!(arg instanceof Array)) { arg = Array.prototype.slice.ca...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/11245
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type narrowing not working as expected","articleBody":"**TypeScript Version:** 2.0.2 RC\n\n**Code**\nThis code fails:\n\n``` ts\nfunction f1(arg: string[]) {}\n\nfunction f2(arg: ArrayLike\u003cstring> | string[]) {\n if (!(arg instanceof Array)) {\n arg = Array.prototype.slice.call(arg) as string[];\n }\n // -> arg is always a string[] here\n f1(arg); // supplied parameter does not match signature...\n}\n```\n\nHowever, this code shows no error:\n\n``` ts\nfunction f1(arg: string[]) {}\n\nfunction f2(arg: string | string[]) {\n if (!(arg instanceof Array)) {\n arg = Array.prototype.slice.call(arg) as string[];\n }\n f1(arg);\n}\n```\n\n**Expected behavior:**\nThe narrowing should recognize that `arg` must be a `string[]` when calling `f1`.\n\n**Actual behavior:** \nThe narrowing seems not to take place when one type is a subset of another, e.g. `ArrayLike\u003cstring>` is a subset of `T[]`. The issue can also be shown with this signature: `f2(arg: {length: number} | string[])`\n","author":{"url":"https://github.com/avonwyss","@type":"Person","name":"avonwyss"},"datePublished":"2016-09-29T12:58:17Z","url":"https://github.com/microsoft/TypeScript/issues/11245"}
| 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:ebb07b2d-cbdc-a9e1-bc7e-ad28d9a97d3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A87E:2E7EBB:10B8C54:152C6E3:6B011210 |
| html-safe-nonce | cf5f1f275f63cbb084ec16a805d20a51c5efa2d392569a6ba0d4b7612250e06c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODdFOjJFN0VCQjoxMEI4QzU0OjE1MkM2RTM6NkIwMTEyMTAiLCJ2aXNpdG9yX2lkIjoiMTk0MTg2NjgzMTEyMDM0ODMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3eb1e2de30fe64c0798559bd56935319180366122a8ef6c6f219cd5c115b1e69 |
| hovercard-subject-tag | issue:180042071 |
| 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/11245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a0845ec29cf73bbb1226984930161e6f29a31e250d86dc57382919e0a74a134/microsoft/TypeScript/issues/11245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a0845ec29cf73bbb1226984930161e6f29a31e250d86dc57382919e0a74a134/microsoft/TypeScript/issues/11245 |
| og:image:alt | TypeScript Version: 2.0.2 RC Code This code fails: function f1(arg: string[]) {} function f2(arg: ArrayLike |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | avonwyss |
| 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