Title: Each member of the union type has signatures, but none of those signatures are compatible with each other · Issue #33591 · microsoft/TypeScript · GitHub
Open Graph Title: Each member of the union type has signatures, but none of those signatures are compatible with each other · Issue #33591 · microsoft/TypeScript
X Title: Each member of the union type has signatures, but none of those signatures are compatible with each other · Issue #33591 · microsoft/TypeScript
Description: TypeScript Version: 3.6.3 Search Terms: array.map, expression is not callable, union type signatures, Code The following code is the exact same code as in this codesandbox https://codesandbox.io/s/lingering-sun-7itgj interface Product_re...
Open Graph Description: TypeScript Version: 3.6.3 Search Terms: array.map, expression is not callable, union type signatures, Code The following code is the exact same code as in this codesandbox https://codesandbox.io/s/...
X Description: TypeScript Version: 3.6.3 Search Terms: array.map, expression is not callable, union type signatures, Code The following code is the exact same code as in this codesandbox https://codesandbox.io/s/...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33591
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Each member of the union type has signatures, but none of those signatures are compatible with each other","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.6.3\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\narray.map, expression is not callable, union type signatures,\r\n\r\n**Code**\r\n\r\n_The following code is the exact same code as in this codesandbox_\r\nhttps://codesandbox.io/s/lingering-sun-7itgj\r\n\r\n```ts\r\ninterface Product_result {\r\n __typename: 'Product'\r\n id: number\r\n description: string | null\r\n}\r\ninterface Campaign_result {\r\n __typename: 'Campaign'\r\n id: number\r\n products: (Product_result | null)[] | null\r\n}\r\n\r\n\r\ninterface Product {\r\n id: number\r\n description: string\r\n specific: boolean\r\n}\r\ninterface Campaign {\r\n products: Product[]\r\n}\r\n\r\ntype CompoundType = Campaign_result | Campaign\r\n\r\n/* --- */\r\n\r\nconst props: { campaign?: Campaign_result } = {}\r\nconst emptyCampaign: Campaign = {\r\n products: []\r\n}\r\n\r\nconst initialData: CompoundType = props.campaign || emptyCampaign\r\n\r\n\r\n/*\r\nCannot invoke an expression whose type lacks a call signature. Type '\r\n (\u003cU>(callbackfn: (value: Product_result, index: number, array: Product_result[]) => U, thisArg?: any) => U[])\r\n | (\u003cU>(callbackfn: (value: Product, index: number, array: Product[]) => U, thisArg?: any) => U[])\r\n' has no compatible call signatures.\r\n\r\nproduct inside map is any, but I know `id` is there\r\n*/\r\ninitialData.products.map(product => product.id)\r\n\r\n\r\n// product is { description: string, id: number } - as expected\r\nconst product = initialData.products[0] \r\n\r\n// product inside map is { description: string, id: number } - as expected\r\n;(initialData.products as Array\u003cCompoundType['products'][0]>).map(product => product.id)\r\n\r\n\r\n/* interestingly */\r\n\r\ntype T01 = Array\u003cCompoundType['products'][0]> // T01: (Product_result | Product)[] - I can actually have mix of both. Products that were fetched and Products added via a Form\r\ntype T02 = CompoundType['products'] // T02: Product_result[] | Product[]\r\n\r\ndeclare const v1: T01\r\nv1.map(product => product) // OK\r\n\r\ndeclare const v2: T02\r\nv2.map(product => product) // NOK\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n\r\nI know `id` is there, so this should work\r\n`initialData.products.map(product => product.id)`\r\n\r\nThis workaround works\r\n`(initialData.products as Array\u003cCompoundType['products'][0]>).map(product => product.id)`\r\n\r\n**Actual behavior:**\r\n\r\nThe map gives a non compatible call signature error (as in the snippet above), and the product inside is any.\r\n\r\n\r\n**Related**\r\nTypeScript 3.3 - Improved behavior for calling union types\r\nhttps://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-3.html#caveats","author":{"url":"https://github.com/ackvf","@type":"Person","name":"ackvf"},"datePublished":"2019-09-25T13:57:47Z","url":"https://github.com/microsoft/TypeScript/issues/33591"}
| 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:6b2b356d-9434-e3ee-a63c-77d197348f99 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A2C4:399E4B:80EEA7:AD4505:6B00DE93 |
| html-safe-nonce | 085856d3fa06b2e3d913030ce031cef204ca2f032038c203c81114f433d3b548 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkM0OjM5OUU0Qjo4MEVFQTc6QUQ0NTA1OjZCMDBERTkzIiwidmlzaXRvcl9pZCI6Ijg2NTkzMTk0NTU0NTQ2NTAwMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 60035962db1f1f0357d64872a71727fbdd77d46bfd7eafea7544c0e012d41e21 |
| hovercard-subject-tag | issue:498305239 |
| 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/33591/issue_layout |
| twitter:image | https://opengraph.githubassets.com/87995f9425dac0d2993dba0a73d56fbcbf181e6ec7d6f6672561afbaa44b6c44/microsoft/TypeScript/issues/33591 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/87995f9425dac0d2993dba0a73d56fbcbf181e6ec7d6f6672561afbaa44b6c44/microsoft/TypeScript/issues/33591 |
| og:image:alt | TypeScript Version: 3.6.3 Search Terms: array.map, expression is not callable, union type signatures, Code The following code is the exact same code as in this codesandbox https://codesandbox.io/s/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ackvf |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width