Title: “Type instantiation is excessively deep and possibly infinite” but only in a large codebase · Issue #34933 · microsoft/TypeScript · GitHub
Open Graph Title: “Type instantiation is excessively deep and possibly infinite” but only in a large codebase · Issue #34933 · microsoft/TypeScript
X Title: “Type instantiation is excessively deep and possibly infinite” but only in a large codebase · Issue #34933 · microsoft/TypeScript
Description: TypeScript Version: 3.7.2, 3.8.0-dev.20191102 (worked in 3.6) Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Mapped types Generics Conditional types Code Note: this issue manifests itself only in our ...
Open Graph Description: TypeScript Version: 3.7.2, 3.8.0-dev.20191102 (worked in 3.6) Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Mapped types Generics Conditional types Code Note: ...
X Description: TypeScript Version: 3.7.2, 3.8.0-dev.20191102 (worked in 3.6) Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Mapped types Generics Conditional types Code Note: ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/34933
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"“Type instantiation is excessively deep and possibly infinite” but only in a large codebase","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.7.2, 3.8.0-dev.20191102 (worked in 3.6)\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\n\r\n- Type instantiation is excessively deep and possibly infinite.ts(2589)\r\n- Mapped types\r\n- Generics\r\n- Conditional types\r\n\r\n**Code**\r\n\r\nNote: **this issue manifests itself only in our codebase**. When you run the same code in TypeScript Playground, it seems to be working fine.\r\n\r\nThe snippet is hardly minimal, but I reduced it as much as I could. I recorded [a video](https://streamable.com/pjkrk) where exactly the same code yields an error different than the one in TypeScript Playground. I tried with two versions of TypeScript: `3.7.2` and `3.8.0-dev.20191102`. It worked correctly with `3.6`.\r\n\r\nSince @sheetalkamat and @DanielRosenwasser have access to our repository, you're welcome to have a look at [this PR](https://github.com/unsplash/unsplash-web/pull/4243). Copy-paste the code below anywhere in the project to see the error.\r\n\r\nThe versions of types used:\r\n\r\n- `@types/history@4.7.3`\r\n- `@types/react@16.9.11`\r\n- `@types/react-router-dom@5.1.0`\r\n- `@types/recompose@0.30.7`\r\n\r\n**Note**: Interestingly enough, if you change:\r\n\r\n```diff\r\n- declare const Button: React.FunctionComponent\u003cOmit\u003cProps, never>>;\r\n+ declare const Button: React.FunctionComponent\u003cProps>;\r\n```\r\n\r\nit works again despite the fact `Omit\u003cProps, never>` should be the same as just `Props`.\r\n\r\n\u003cdetails>\r\n\r\n\u003csummary>Source code\u003c/summary>\r\n\r\n```ts\r\nimport { History } from 'history'; // \"4.7.3\"\r\nimport * as React from 'react'; // \"16.9.11\"\r\nimport { LinkProps, RouteComponentProps, withRouter } from 'react-router-dom'; // \"5.1.0\"\r\nimport { getDisplayName } from 'recompose'; // \"0.30.7\"\r\n\r\ndeclare function isDefined\u003cT>(candidate: T | null | undefined): candidate is T;\r\ndeclare function isString(value?: any): value is string;\r\n\r\ntype ObjectOmit\u003cT extends K, K> = Omit\u003cT, keyof K>;\r\n\r\ntype OnClick = NonNullable\u003cReact.ComponentProps\u003c'button'>['onClick']>;\r\n\r\ntype OnClickProp = {\r\n /** If there is a custom click handler, we must preserve it. */\r\n onClick?: OnClick;\r\n};\r\n\r\ntype ProvidedProps = OnClickProp;\r\n\r\ntype InputProps = OnClickProp & {\r\n /** Note: we want this helper to work with all sorts of modals, not just those backed by query\r\n * parameters (e.g. `/photo/:id/info`), which is why this must accept a full location instead of a\r\n * `Modal` type.\r\n * */\r\n to: Exclude\u003cLinkProps['to'], Function>;\r\n};\r\n\r\nconst buildClickHandler = ({\r\n to,\r\n onClick,\r\n history,\r\n}: InputProps & {\r\n history: History;\r\n}): OnClick => {\r\n const navigate = () => {\r\n // https://github.com/Microsoft/TypeScript/issues/14107\r\n isString(to) ? history.push(to) : history.push(to);\r\n };\r\n\r\n return event => {\r\n [onClick, navigate].filter(isDefined).forEach(callback => callback(event));\r\n };\r\n};\r\n\r\n/** See the test for an example of usage. */\r\nexport const enhance = \u003cComposedProps extends ProvidedProps>(\r\n ComposedComponent: React.ComponentType\u003cComposedProps>,\r\n) => {\r\n type PassThroughComposedProps = ObjectOmit\u003cComposedProps, ProvidedProps>;\r\n type OwnProps = InputProps & RouteComponentProps\u003cnever> & PassThroughComposedProps;\r\n type Props = OwnProps;\r\n\r\n const displayName = `CreateModalLink(${getDisplayName(ComposedComponent)})`;\r\n\r\n const ModalLink: React.FunctionComponent\u003cProps> = ({\r\n to,\r\n onClick,\r\n\r\n history,\r\n // We specify these just to omit them from rest props below\r\n location,\r\n match,\r\n staticContext,\r\n\r\n ...passThroughComposedProps\r\n }) => {\r\n const clickHandler = buildClickHandler({ to, onClick, history });\r\n\r\n const composedProps: ComposedProps = {\r\n // Note: this is technically unsafe, since the composed component may have props\r\n // with names matching the ones we're omitting.\r\n // https://github.com/microsoft/TypeScript/issues/28884#issuecomment-503540848\r\n ...((passThroughComposedProps as unknown) as PassThroughComposedProps),\r\n onClick: clickHandler,\r\n } as ComposedProps;\r\n\r\n return \u003cComposedComponent {...composedProps} />;\r\n };\r\n\r\n ModalLink.displayName = displayName;\r\n\r\n return withRouter(ModalLink);\r\n};\r\n\r\ntype Props = React.ComponentPropsWithoutRef\u003c'button'> &\r\n Required\u003cPick\u003cReact.ComponentPropsWithoutRef\u003c'button'>, 'type'>>;\r\n\r\n/**\r\n * This one errors.\r\n */\r\ndeclare const Button: React.FunctionComponent\u003cOmit\u003cProps, never>>;\r\n\r\n/**\r\n * This one works.\r\n */\r\n// declare const Button: React.FunctionComponent\u003cProps>;\r\n\r\nconst EnhancedButton = enhance(Button);\r\n\r\n/**\r\n * Type instantiation is excessively deep and possibly infinite.ts(2589).\r\n */\r\n() => \u003cEnhancedButton>\u003c/EnhancedButton>;\r\n\r\n\r\n```\r\n\r\n\u003c/details>\r\n\r\n**Expected behavior:**\r\n\r\nI should get a proper error about missing properties (not the one about type instantiation):\r\n\r\n```\r\nType '{}' is missing the following properties from type 'Readonly\u003cPick\u003cOwnProps, \"form\" | \"style\" | \"title\" | \"onClick\" | \"to\" | \"key\" | \"autoFocus\" | \"disabled\" | \"formAction\" | \"formEncType\" | \"formMethod\" | \"formNoValidate\" | \"formTarget\" | ... 252 more ... | \"onTransitionEndCapture\">>': to, type(2739)\r\n```\r\n\r\n**Actual behavior:**\r\n\r\nI'm getting this:\r\n\r\n```\r\nType instantiation is excessively deep and possibly infinite.ts(2589).\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\n[Playground Link](https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAbzgCWAZxtAnnAvnAMyghDgHIALdTKLMgbgChRJY4AqOAQzTgCUAplwDG8IiXJQhohs3DR4SADLAAdgGsACsTBoANPwgBXGAIDCJSKoGqY2iLoMB3YDAp9jpqHkLFSZKREYAFpiEwEoYIATElkWBUQ4AHMBGAARdDAAGy4sADkuEAEfcX8pYUsINAFZRiiBYRypQiNVUWAIVTh0NIECNQEogB4AFQA+AAphLlUo4CiuUwAuOBG4AB84VSMsrI24Vvr+6yiAShXp2fnF4vRVpnrGrmaCVvbO7rQAZRgoNSSJgA3LhZIwCAD8K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KAWXnT25p9v2A7tzsEop0Vigzjk067dEA3FuA5jQbJcgKIo5XQsxAlMWTnwMomABIEBSdJMhyfJ4ImQPBgLy3TlwU50I72NOmY8eQUnk3pFLCy2isiULdsIYHZ8oHvwgULatB9RAp2u7sGfuqGoAdWKXuDRgAEHonuaocBPzMWPCQVw349ykFKHAAseZg54n3BAJwO1eL8UEt-B8iwqJ4IwIsaUFhbAq3frVOAWoaGwSrr7Yw-tV4J10JWLegMdpdyTDKTysxvLshcm5DyXkIi+UfgYV+BhP60DwOTeyVCuF1xYWgFYzCW4Px-vKd8AgVgMRoqYKiqhpQgiyDgVoaAuAEAEAYNAag2JwOKL1BWgw956ktvgnAqZiwwQSjtTR55qIlSKIxAhVBUQOKrNYXg64Ag8zJE1f4ykqGaIoE1FqbUOpdR6iQQMZIppVAFKNa2AhJrTVGugeazNAwACYAAc9SVoAGIKlgl6kUWwwQACs60ADMnSVrrVqStWpfjqE0ImBMOh3sGFGCYUo8cPADgaFUBg1QVVFmV2mTXNRCVyKjNfhcGsvD0wRDwfgRZOyY67wDJ9b6XRI7OINm4gGCAaHZKjvXGO+BAxJ0pvIuAh8siTy1D3PuS9B7slBYvAeAhd63J+muDqed4aAsnnI96TcPbB3ZKbUs68DQJV-h1TwggCDGlNE1Tolo5yVkEOBYAUhhiaAdBqU+5tnnxRjkSn8JhSXkrNFSx25Am6WhsowJc-pOA+zuJ0YoERiBQDQEkoWdQGhNEcfveAAAhAVqgT7anPu8K+HKhjh1vglcGf0IhjDFRK6C0q7zWBPFAdQSrJUVnqt3NVzwNVOW1bq-VZtDWX3xRHB26Iu4aVUFLNiUQdWUq6OySWMw2ITHjeaOR4qQyStWO7YSMAtzABIR8O41I2JzWAMWUxXr2LcFmDBKotjVQ4GImoVwKEYBoAmNUzptSACcpxlUVgmM7FkQwo0xsGOm6yQxAwTpTVO3VYqgA)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n\r\n- #32735\r\n- #34850","author":{"url":"https://github.com/karol-majewski","@type":"Person","name":"karol-majewski"},"datePublished":"2019-11-06T00:06:49Z","url":"https://github.com/microsoft/TypeScript/issues/34933"}
| 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:7dcfd295-da1a-ab0c-897d-3c7d83998095 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE0A:1DC4CC:7DDA0F:A7EA22:6B01AE42 |
| html-safe-nonce | 4ee9f91ffafb6dc6b2a6bcb45f650a66e25f6d3ab1447e5a4fd7374e3a26084e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTBBOjFEQzRDQzo3RERBMEY6QTdFQTIyOjZCMDFBRTQyIiwidmlzaXRvcl9pZCI6Ijc4MzMwODA2MDY1NTk5NDAxNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 53e846c8441daaf0bd3dbfa00252f6e8cf6f84e39014c2a41f5931fb4105665b |
| hovercard-subject-tag | issue:518141824 |
| 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/34933/issue_layout |
| twitter:image | https://opengraph.githubassets.com/372b9d982949e39bfc7b39b9b01f1b9e808a90a041e78ba496cc32412c7ed4a7/microsoft/TypeScript/issues/34933 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/372b9d982949e39bfc7b39b9b01f1b9e808a90a041e78ba496cc32412c7ed4a7/microsoft/TypeScript/issues/34933 |
| og:image:alt | TypeScript Version: 3.7.2, 3.8.0-dev.20191102 (worked in 3.6) Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Mapped types Generics Conditional types Code Note: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | karol-majewski |
| 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