Title: This is not for TypeScript but for everybody facing type instantiation too deep · Issue #34850 · microsoft/TypeScript · GitHub
Open Graph Title: This is not for TypeScript but for everybody facing type instantiation too deep · Issue #34850 · microsoft/TypeScript
X Title: This is not for TypeScript but for everybody facing type instantiation too deep · Issue #34850 · microsoft/TypeScript
Description: Hold on everybody facing "Type instantiation is excessively deep and possibly infinite" I think I've just found a solution for type instantiation too deep error in https://github.com/graphql-editor/graphql-zeus this repo. The solution is...
Open Graph Description: Hold on everybody facing "Type instantiation is excessively deep and possibly infinite" I think I've just found a solution for type instantiation too deep error in https://github.com/graphql-editor...
X Description: Hold on everybody facing "Type instantiation is excessively deep and possibly infinite" I think I've just found a solution for type instantiation too deep error in https://github.com/...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/34850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"This is not for TypeScript but for everybody facing type instantiation too deep","articleBody":"\r\n\r\nHold on everybody facing \"Type instantiation is excessively deep and possibly infinite\" I think I've just found a solution for `type instantiation too deep error` in \r\nhttps://github.com/graphql-editor/graphql-zeus this repo. The solution is to create a conditional type even if you know that the type is the type. I can crawl out the rabbit hole now!\r\n\r\n```ts\r\n\r\n\r\ntype Func\u003cP extends any[], R> = (...args: P) => R;\r\ntype AnyFunc = Func\u003cany, any>;\r\n\r\ntype IsType\u003cM, T, Z, L> = T extends M ? Z : L;\r\ntype IsScalar\u003cT, Z, L> = IsType\u003cstring | boolean | number, T, Z, L>;\r\ntype IsObject\u003cT, Z, L> = IsType\u003c{} | Record\u003cstring,any>, T, Z, L>;\r\n\r\ntype WithTypeNameValue\u003cT> = T & {\r\n __typename?: true;\r\n};\r\n\r\ntype AliasType\u003cT> = WithTypeNameValue\u003cT> & {\r\n __alias?: Record\u003cstring, WithTypeNameValue\u003cT>>;\r\n};\r\n\r\nexport type AliasedReturnType\u003cT> = IsObject\u003cT,{\r\n [P in keyof T]: T[P];\r\n} &\r\nRecord\u003c\r\n string,\r\n {\r\n [P in keyof T]: T[P];\r\n }\r\n>,never>;\r\n\r\nexport type ResolverType\u003cF> = F extends Func\u003cinfer P, any>\r\n ? P[0]\r\n : undefined;\r\n\r\ntype ArgsType\u003cF extends AnyFunc> = F extends Func\u003cinfer P, any> ? P : never;\r\ntype OfType\u003cT> = T extends Array\u003cinfer R> ? R : T;\r\ntype FirstArgument\u003cF extends AnyFunc> = OfType\u003cArgsType\u003cF>>;\r\n\r\ninterface GraphQLResponse {\r\n data?: Record\u003cstring, any>;\r\n errors?: Array\u003c{\r\n message: string;\r\n }>;\r\n}\r\n\r\nexport type State\u003cT> = {\r\n [P in keyof T]?: T[P] extends (Array\u003cinfer R> | undefined)\r\n ? Array\u003cAliasedReturnType\u003cState\u003cR>>>\r\n : T[P] extends AnyFunc\r\n ? AliasedReturnType\u003cState\u003cReturnType\u003cT[P]>>>\r\n : IsScalar\u003cT[P], T[P], IsObject\u003cT[P],AliasedReturnType\u003cState\u003cT[P]>>,never>>;\r\n};\r\n\r\nexport type PlainObject\u003cT> = {\r\n [P in keyof T]?: T[P] extends (Array\u003cinfer R> | undefined)\r\n ? Array\u003cPlainObject\u003cR>>\r\n : T[P] extends AnyFunc\r\n ? PlainObject\u003cReturnType\u003cT[P]>>\r\n : IsScalar\u003cT[P], T[P], IsObject\u003cT[P],PlainObject\u003cT[P]>,never>>;\r\n};\r\n\r\ntype ResolveValue\u003cT> = T extends Array\u003cinfer R>\r\n ? SelectionSet\u003cR>\r\n : T extends AnyFunc\r\n ? IsScalar\u003c\r\n ReturnType\u003cT>,\r\n [FirstArgument\u003cT>],\r\n [FirstArgument\u003cT>, SelectionSet\u003cOfType\u003cReturnType\u003cT>>>]\r\n >\r\n : IsScalar\u003cT, T extends undefined ? undefined : true, IsObject\u003cT,SelectionSet\u003cT>,never>>;\r\n\r\nexport type SelectionSet\u003cT> = IsScalar\u003c\r\n T, T extends undefined ? undefined : true\r\n, IsObject\u003cT,AliasType\u003c\r\n {\r\n [P in keyof T]?: ResolveValue\u003cT[P]>;\r\n }\r\n >,never>>;\r\n\r\ntype GraphQLReturner\u003cT> = T extends Array\u003cinfer R> ? SelectionSet\u003cR> : SelectionSet\u003cT>;\r\n\r\ntype OperationToGraphQL\u003cV,T> = (o: GraphQLReturner\u003cV>) => Promise\u003cAliasedReturnType\u003cState\u003cT>>>;\r\n\r\ntype ResolveApiField\u003cT> = T extends Array\u003cinfer R>\r\n ? IsScalar\u003cR, R, State\u003cR>>\r\n : T extends AnyFunc\r\n ? IsScalar\u003cOfType\u003cReturnType\u003cT>>, T, State\u003cOfType\u003cReturnType\u003cT>>>>\r\n : IsScalar\u003cT, T, State\u003cT>>;\r\n\r\ntype ApiFieldToGraphQL\u003cV,T> = (o: ResolveValue\u003cV>) => Promise\u003cResolveApiField\u003cT>>;\r\n\r\ntype fetchOptions = ArgsType\u003ctypeof fetch>;\r\n```\r\n\r\nSo whats going on here? I had a problem with this error on large schemas, but... not anymore after adding `IsObject` type. The main thing is to drop the type in the type system as `never` even if you know it is a correct type. This is the only way as you tell the compiler that going down is conditional.\r\n\r\n@orta can you look at it? Correct me if I am wrong but it looks like when the conditional types are closed somehow you can create very generic types.","author":{"url":"https://github.com/aexol","@type":"Person","name":"aexol"},"datePublished":"2019-10-31T18:25:33Z","url":"https://github.com/microsoft/TypeScript/issues/34850"}
| 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:58923a50-5862-5e3e-3fb4-f549ddd08e03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D20:E3C4F:3394A51:41D626F:6B01E377 |
| html-safe-nonce | 2ef49e6024cef1c2d00e75111cce3f9fb78aab3718056dc3171c38707fc61921 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDIwOkUzQzRGOjMzOTRBNTE6NDFENjI2Rjo2QjAxRTM3NyIsInZpc2l0b3JfaWQiOiI4MDMwNzg5MDUyNjYyOTk3NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 15292a597535bbdef5ed6904516b40dfdd89087dbd18021d48c265311c814383 |
| hovercard-subject-tag | issue:515650563 |
| 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/34850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dea14523218de9d2f300131b1e7326837733ae77c6235b322cbd6b581714ff8d/microsoft/TypeScript/issues/34850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dea14523218de9d2f300131b1e7326837733ae77c6235b322cbd6b581714ff8d/microsoft/TypeScript/issues/34850 |
| og:image:alt | Hold on everybody facing "Type instantiation is excessively deep and possibly infinite" I think I've just found a solution for type instantiation too deep error in https://github.com/graphql-editor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aexol |
| 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