aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
81 stars 71 forks source link

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

Open sevenkkk opened 1 month ago

sevenkkk commented 1 month ago

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:

chrisbonifacio commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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