Title: Using this-type with intersection type makes it possible to simulate HKT · Issue #40928 · microsoft/TypeScript · GitHub
Open Graph Title: Using this-type with intersection type makes it possible to simulate HKT · Issue #40928 · microsoft/TypeScript
X Title: Using this-type with intersection type makes it possible to simulate HKT · Issue #40928 · microsoft/TypeScript
Description: TypeScript Version: Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8 Search Terms: this-type, this type, intersection, HKT, higher kinded type Code export interface HKT { param: unknown; result: unknown...
Open Graph Description: TypeScript Version: Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8 Search Terms: this-type, this type, intersection, HKT, higher kinded type Code export interfa...
X Description: TypeScript Version: Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8 Search Terms: this-type, this type, intersection, HKT, higher kinded type Code export interfa...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/40928
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using this-type with intersection type makes it possible to simulate HKT ","articleBody":"\u003c!-- 🚨 STOP 🚨 STOP 🚨 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:** Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** this-type, this type, intersection, HKT, higher kinded type\r\n\r\n**Code**\r\n\r\n```ts\r\nexport interface HKT {\r\n param: unknown;\r\n result: unknown;\r\n}\r\n\r\ninterface NotHKT extends HKT {\r\n result: this['param'] extends true ? false : true;\r\n}\r\n\r\ninterface FstHKT extends HKT {\r\n result: this['param'] extends [infer A, infer _] ? A : never;\r\n}\r\n\r\ninterface ArrayHKT extends HKT {\r\n result: Array\u003cthis['param']>;\r\n}\r\n\r\nexport type Apply\u003cf extends HKT, x>\r\n = (f & { param: x })['result'];\r\n\r\ntype Test1 = Apply\u003cNotHKT, true> // be deducedd to `false`\r\ntype Test2 = Apply\u003cFstHKT, [string, boolean]> // be deduced to `string`\r\ntype Test3 = Apply\u003cArrayHKT, number> // be deduced to `number[]`\r\n```\r\n\r\n**Expected behavior:** I expected that reduction of `this` type doesn't depends on type that is intersected with.\r\n\r\n**Actual behavior:** reduction of `this` type depends on type that is intersected with.\r\n\r\nThe actual behavior makes sense to me(at least). It's not hard to accept its behavior. However, It looks like unintended behavior or bug (just like recursive conditional type before) so that I can't certain it's okay to use this. **Is this idea safe to use?**\r\n\r\n**[Playground Link](https://www.typescriptlang.org/play?ts=4.1.0-dev.20201003#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgCQGkAVOAbwCg44xMpMBbALjgFckBrJCAdyQG4qcKMADOrADYwW7LrwEUAvhQrJUGHHgByEGEVKhUSACaiCJckJHipLGAAsEogNoByWvQauAunEPATMxgoVjwAfjgsCVE8OxDgQWVVFDQsXDgAMVE9C39A81JKamtJaTgHJzcPRh8-ECNTOGdkdDQ4AEEAGkQkVqg4AH1fCPa4FiRgADc0RJU1VM0OqHoAT306hrN1ouExUpZ25cwVgB4Kl3c6Gu8APlmKUEhYcpWwPHawMAlT9A2Axv03RANyEAF44AAKX4AMnINCuzDgIDgigAlG4SlIfIIKDBXnhiGIYABGODgj5fU46HLEbrBUI3OAAeiZcAARnhjMBjKxcMZjOUIHAAAZRGLC3H4uCE7IAJjJHU+3xOWRp3Wc2SgyAA5t02RAIBJgJgkLdmayOXAuTy+YKRZqdRK8W9pUSAMwKinKw6rQFwJCsBgcqCMlnsznc3ncu3CgNBtDObzCoA)**\r\n","author":{"url":"https://github.com/ENvironmentSet","@type":"Person","name":"ENvironmentSet"},"datePublished":"2020-10-03T18:59:54Z","url":"https://github.com/microsoft/TypeScript/issues/40928"}
| 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:cf4bb418-e3b0-f7d3-a064-d58d4126ea7c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A900:19E4BB:230CC26:2CB2B82:6B018386 |
| html-safe-nonce | e0c6541517236b224de643ecbd509368a918ef1eecfbb46441015ecb6d09c4df |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTAwOjE5RTRCQjoyMzBDQzI2OjJDQjJCODI6NkIwMTgzODYiLCJ2aXNpdG9yX2lkIjoiMTE1NDE5OTgyMTgxMzM4NDA3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d3dc185e291be21b44ef3ec9b2e02f241a6446f04445fede349ab89f4f99bacd |
| hovercard-subject-tag | issue:714154533 |
| 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/40928/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8d940162f8fab46cba5496c6f8af4655eab1039adbd8f2414cf7a9d26b2b9363/microsoft/TypeScript/issues/40928 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8d940162f8fab46cba5496c6f8af4655eab1039adbd8f2414cf7a9d26b2b9363/microsoft/TypeScript/issues/40928 |
| og:image:alt | TypeScript Version: Lastly tested in v4.1.0-dev20201003, but this has been existing at least since v3.8 Search Terms: this-type, this type, intersection, HKT, higher kinded type Code export interfa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ENvironmentSet |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width