Open asp3 opened 4 months ago
export const serverClient = generateServerClientUsingCookies({
config: awsConfig,
cookies,
}) as V6ClientSSRCookies;
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 V6ClientSSRCookies
at every level, and the errors seem to go away.
export const serverClient = generateServerClientUsingCookies({
config: awsConfig,
cookies,
}) <<< as V6ClientSSRCookies >>> (adding this)
or
export const serverClient: <<< as V6ClientSSRCookies >>> (adding this) = generateServerClientUsingCookies({
config: awsConfig,
cookies,
})
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 5.3.2
or so.
@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 as V6ClientSSRCookies
is perfectly valid and I would just stick with that while we look into improving the underlying types.
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:
export type Schema = ClientSchema<typeof schema>;
in resource.ts
But more annoyingly, calls like this:
await client.models.MyModel.update(...)
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 Client
, but Client
is not a strict supertype of the V6ClientSSRCookies<never>
returned from generateServerClientUsingCookies()
(i.e. V6ClientSSRCookies<never>
is not assignable to the parameter of type Client
since subscriptions don't exist on the server).
Also, per @asp3's and @iartemiev's comments, I am unable to see if explicitly declaring the type of the client to be V6ClientSSRCookies
resolves the issue, since that type (along with other useful "reference" types used internally) are not exported. So I cannot import that type for use. I'm curious as to how you are able to access those types, given the recommended way of using aws-amplify category APIs in V6. The seemingly closest exported type is ClientUsingSSRCookies
, which is shown above. I assume this is the correct consumer-facing type for this usage.
aws-amplify: 6.0.27 @aws-amplify/adapter-nextjs: 1.0.27 typescript: 5.4.4 VSCode: 1.87.2 The VSCode workspace is configured to use the project's version of TypeScript.
+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.
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