Title: 3.9 regression: TS2322 error around assignment of an inferred intersection to a union · Issue #38542 · microsoft/TypeScript · GitHub
Open Graph Title: 3.9 regression: TS2322 error around assignment of an inferred intersection to a union · Issue #38542 · microsoft/TypeScript
X Title: 3.9 regression: TS2322 error around assignment of an inferred intersection to a union · Issue #38542 · microsoft/TypeScript
Description: TypeScript Version: 3.9.2, 4.0.0-dev.20200512 Search Terms: TS2322, "is not assignable to type" Code import * as reflect from 'jsii-reflect'; // Version ^1.5.0 export type ApiElement = reflect.Type | reflect.TypeMember | reflect.EnumMemb...
Open Graph Description: TypeScript Version: 3.9.2, 4.0.0-dev.20200512 Search Terms: TS2322, "is not assignable to type" Code import * as reflect from 'jsii-reflect'; // Version ^1.5.0 export type ApiElement = reflect.Type...
X Description: TypeScript Version: 3.9.2, 4.0.0-dev.20200512 Search Terms: TS2322, "is not assignable to type" Code import * as reflect from 'jsii-reflect'; // Version ^1.5.0 export type ApiElem...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/38542
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"3.9 regression: TS2322 error around assignment of an inferred intersection to a union ","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!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** 3.9.2, 4.0.0-dev.20200512\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** TS2322, \"is not assignable to type\"\r\n\r\n**Code**\r\n\r\n```ts\r\nimport * as reflect from 'jsii-reflect'; // Version ^1.5.0\r\n\r\nexport type ApiElement = reflect.Type | reflect.TypeMember | reflect.EnumMember;\r\n\r\nexport interface Data {\r\n readonly element: ApiElement;\r\n}\r\n\r\n// Note: reflect.Method and reflect.Initializer both directly or indirectly implement reflect.TypeMember\r\nexport function doSomething\u003cT extends (reflect.Method | reflect.Initializer)>(element: T): Data {\r\n if (reflect.Method.isMethod(element)) {\r\n // Type 'T & Method' is not assignable to type 'Type'.\r\n return { element };\r\n }\r\n if (reflect.Initializer.isInitializer(element)) {\r\n // Type 'T & Initializer' is not assignable to type 'Type'.\r\n return { element };\r\n }\r\n // Type checking absolutely fine - why'd previous ones not?\r\n return { element };\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nIt should work like it did in TypeScript 3.8\r\n\r\n**Actual behavior:**\r\n```\r\n$ tsc --build\r\nlib/index.ts:13:14 - error TS2322: Type 'T & Method' is not assignable to type 'ApiElement'.\r\n Type 'T & Method' is not assignable to type 'Type'.\r\n\r\n12 return { element };\r\n ~~~~~~~\r\n\r\n lib/index.ts:6:12\r\n 6 readonly element: ApiElement;\r\n ~~~~~~~\r\n The expected type comes from property 'element' which is declared here on type 'Data'\r\n\r\nlib/index.ts:17:14 - error TS2322: Type 'T & Initializer' is not assignable to type 'ApiElement'.\r\n Type 'T & Initializer' is not assignable to type 'Type'.\r\n\r\n16 return { element };\r\n ~~~~~~~\r\n\r\n lib/index.ts:6:12\r\n 6 readonly element: ApiElement;\r\n ~~~~~~~\r\n The expected type comes from property 'element' which is declared here on type 'Data'\r\n```\r\n\r\n**Playground Link:** I stored my repro at https://github.com/RomainMuller/TypeScript39-Bug (public)\r\n\r\n**Related Issues:** It appears likely related to the breaking change in #37195 (but not certain)\r\n","author":{"url":"https://github.com/RomainMuller","@type":"Person","name":"RomainMuller"},"datePublished":"2020-05-13T14:51:34Z","url":"https://github.com/microsoft/TypeScript/issues/38542"}
| 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:ae08f0a0-0d5b-7ca2-c609-8f66777ee421 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97BE:B1B84:2E8EBE:3B2A24:6B0102A0 |
| html-safe-nonce | ec9c81a351b5c34f28cb1a477515fdaba2a8bc6bd48fb77dd140f049173a61fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0JFOkIxQjg0OjJFOEVCRTozQjJBMjQ6NkIwMTAyQTAiLCJ2aXNpdG9yX2lkIjoiMTQwMDAyMDM3MjMyOTM5ODk0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa6e8ecd983e2a8ce734a8cbc3c952ef2c30c66929d5102065685c2094739c7d |
| hovercard-subject-tag | issue:617515870 |
| 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/38542/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bf0027e6314daf71b5a0ca4a8be7837eb9a54194aa73ad13124829c52a05047a/microsoft/TypeScript/issues/38542 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bf0027e6314daf71b5a0ca4a8be7837eb9a54194aa73ad13124829c52a05047a/microsoft/TypeScript/issues/38542 |
| og:image:alt | TypeScript Version: 3.9.2, 4.0.0-dev.20200512 Search Terms: TS2322, "is not assignable to type" Code import * as reflect from 'jsii-reflect'; // Version ^1.5.0 export type ApiElement = reflect.Type... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RomainMuller |
| 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