-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type instantiation is excessively deep and possibly infinite. TS(2589) #12973
Comments
fixed for me with a simple addition of the type here. not sure if it really changes anything |
I've attempted to repro this to no avail. Are you seeing this at build time, or only in the IDE? |
@svidgen This is just at an IDE level, doesn't really cause any build issues. To fix the red underlines, I just explicitly set the types to
or
|
Are you using VS Code? If so, can you confirm VS Code is configured (or has recognized) the correct version of typescript? I'm having a hard time taking a screenshot of this menu while it's actually open, but I'm looking for what the curly-brace menu shows you here: E.g., I'd expect it to be |
@svidgen Yep, its 5.3.2 |
Gotcha. Thanks for checking. Leaving in pending triage for @nadetastic to try to repro and/or ask followups. |
@asp3 - could you also give us an idea of the size of your schema? Specifically, is your schema particularly large (many models, or many fields per model), or complex (complex auth rules, a high degree of model connections, etc)? Thank you!! |
@asp3 - I'm able to repro this. The workaround you're using asserting |
OMG. I've solved SO many issues I've been having with Amplify by changing the TS version in VS Code - I was getting the same error on the line:
in resource.ts But more annoyingly, calls like this:
had no type information - accepts and returns 'any'. All of this goes away by changing the VS code TS version.] One for a list of FAQs / common issues, perhaps? |
In the process of porting an Amplify app to TypeScript, I am experiencing this issue when passing a generated Client instance to a function. The function is declared as: import {generateClient, type Client} from "aws-amplify/api";
function doSomething(client: Client) {
return {};
}
// When called:
const client = generateClient();
doSomething(client);
// ^ Type instantiation is excessively deep and possibly infinite.ts(2589)
// const client: V6Client<never> Similarly for server-side clients: import {generateServerClientUsingCookies, type ClientUsingSSRCookies} from '@aws-amplify/adapter-nextjs/api';
import {cookies} from "next/headers";
import amplifyconfig from "../../src/amplifyconfiguration.json";
function doSomething(client: ClientUsingSSRCookies) {
return {};
}
// When called:
const client = generateServerClientUsingCookies({
config: amplifyconfig,
cookies
});
doSomething(client);
// ^ Type instantiation is excessively deep and possibly infinite.ts(2589)
// const client: V6ClientSSRCookies<never> Note that ideally the type for the argument to the function be Also, per @asp3's and @iartemiev's comments, I am unable to see if explicitly declaring the type of the client to be aws-amplify: 6.0.27 |
+1 on this issue. I solved it by upgrading my typescript version to 5.4.5. Note to all who join, that amplify gen 2 basically infers nothing at all without a later version of typescript. |
@patorpey The version of the library from your message is from prior to GA. Can you update to latest versions of everything aws-amplify related and confirm whether you're still seeing an issue? @ChristopherGabba Can you tell me what library versions you have installed? Also, what version of TS were you on prior to upgrading to 5.4.5? (The latest versions of the library do require TS >= 5 for the fully typed DX.) |
I am on amplify 6.4.3 and I was on Typescript 4.9.3 prior to updating to 5.4.5 |
@ChristopherGabba Thanks. That's expected behavior then. The fully typed DX does require TS >= 5. |
@anthonyhoegberg would you be able to provide a schema that reproduces the issue for you? are you sure that your |
Im currently using @aws-amplify/data-schema@1.5.0 so my selection set gets really really deep, i rewrote my schema to remove as many relations as possible and its still overly large, however now it at least don't crash my stuff. |
@svidgen Sorry, I've been away from trying to port this project for a bit. I don't seem to be seeing the previous error, at the moment. However, in one instance of using the result of import {generateClient} from "aws-amplify/api";
const client = generateClient();
const json = await doSomething(client);
// ^ Excessive stack depth comparing types
// 'Prettify<DeepReadOnlyObject<RestoreArrays<UnionToIntersection<DeepPickFromPath<FlatModel, ?[number]>>, FlatModel>>>' and 'Prettify<DeepReadOnlyObject<RestoreArrays<UnionToIntersection<DeepPickFromPath<FlatModel, ?[number]>>, FlatModel>>>'.ts(2321) I assume this is related. Our schema isn't huge, but it does contain cyclic relations. aws-amplify: 6.6.2 |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
No response
Backend
Amplify CLI
Environment information
Describe the bug
First off, I want to say thanks for setting up V6! This new version is a huge upgrade over V5, and we are loving every part of it! While on the path to start strongly typing everything we possibly could, we started running into the issue
Type instantiation is excessively deep and possibly infinite. TS(2589)
while trying to type our server client that is getting passed around. We have a bit of a unique setup, where we have shared code between our mobile and web apps, so when using server context, we pass the serverClient that is generated thoughgenerateServerClientUsingCookies
into our shared code. To keep this strongly typed, we use the type fromwhich seems to lead to that error. when removing this type, the compiler works again. This should be a pretty easily reproducible bug under the conditions. we can of course add a @ts-ignore to each call, but just wondering if there was some easier way to clean this up!
Expected behavior
Be able to use the types provided in api-graphql (
import { V6ClientSSRCookies } from "@aws-amplify/api-graphql"
) without having typescript errors.Reproduction steps
V6ClientSSRCookies
somewheregenerateServerClientUsingCookies
orgenerateClient
Code Snippet
No response
Log output
No response
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: