Skip to content
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

Amplify Gen2 Schema Model Complexity Leads to TS2590 Error in TypeScript Client #2592

Open
2 tasks done
sevenkkk opened this issue Jun 2, 2024 · 8 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working data-schema Gen 2

Comments

@sevenkkk
Copy link

sevenkkk commented Jun 2, 2024

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.20.1

Amplify CLI Version

"@aws-amplify/backend": "^1.0.3",
"@aws-amplify/backend-cli": "^1.0.4",
"@aws-amplify/data-schema": "1.2.8",
"aws-amplify": "^6.3.4",
"typescript": "^5.4.5"

What operating system are you using?

mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

NO

Describe the bug

I'm currently using Amplify Gen2 to manage my backend schema models. However, when the number of schema models exceeds a certain threshold and there are numerous dependencies between them, I encounter a TypeScript error in my client-side code: TS2590: Expression produces a union type that is too complex to represent. This results in the failure of all TypeScript type derivations.
截屏2024-06-02 12 07 15
截屏2024-06-02 12 20 51

Expected behavior

The generated TypeScript types should work correctly regardless of the number of schema models or their dependencies.

Reproduction steps

Here is the repository where my schema definitions are located: https://github.com/sevenkkk/amplify-next-template.git

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@chrisbonifacio
Copy link
Member

Hi @sevenkkk 👋 thanks for raising this issue.

I was able to reproduce the TS error message

image

I'll mark this as a bug for the team to investigate but I don't see that the type suggestions are broken or missing, at least on the latest versions of the amplify backend packages.

Can you try running the following command to ugprade and let us know if your type suggestions performance improves?

npm upgrade @aws-amplify/backend @aws-amplify/backend-cli @aws-amplify/data-schema

@sevenkkk
Copy link
Author

sevenkkk commented Jun 4, 2024

Hi @sevenkkk 👋 thanks for raising this issue.

I was able to reproduce the TS error message

image I'll mark this as a bug for the team to investigate but I don't see that the type suggestions are broken or missing, at least on the latest versions of the amplify backend packages.

Can you try running the following command to ugprade and let us know if your type suggestions performance improves?

npm upgrade @aws-amplify/backend @aws-amplify/backend-cli @aws-amplify/data-schema

I have updated to the latest version, but it is still the same as before.

@chrisbonifacio
Copy link
Member

@sevenkkk thank you for confirming. I've labeled this as a bug for the team to investigate further.

@iartemiev
Copy link
Member

The root cause of this issue is the generated type for the selectionSet option (example). For schemas with highly interconnected models, this type comprises a massive union of literal strings representing valid selection set paths. This type gets eagerly constructed when invoking model-level methods (e.g. client.models.SomeModel.*) even if the selectionSet option is not specified. This is the "union type that is too complex to represent" referred to in the type error.

We've identified potential solutions to this problem and are validating them at the moment. I'll provide another update once we're closer to releasing a bug fix.

@LukaASoban
Copy link

Just wanted to pop in an say that I'm also unable to use Schema types in my code now due to this error. I have a lot of tables/relationships as well.

@ColtonGlasgow13
Copy link

Also coming in for an update - has there been any progress on this issue? The convenience of Amplify's schema typecasting is one of the main reasons to keep using it for a larger project, and this effectively takes that feature away.

@farshid1
Copy link

I have a similar issue given the complexity of my models as well. I do get TS2589 errors (Type instantiation is excessively deep and possibly infinite.) throughout the codebase but I believe the root cause for these 2 errors are the same. the generated type is too complex. As @ColtonGlasgow13 mentioned, this issue defeats the purpose of using this library that advertises a TypeScript-based approach

@JakeGreasleyGIM
Copy link

Also coming for an update. Same issue here: Expression produces a union type that is too complex to represent.ts(2590)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data-schema Gen 2
Projects
None yet
Development

No branches or pull requests

8 participants