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

Typescript error on filter on GSI #2888

Closed
rpostulart opened this issue Sep 18, 2024 · 9 comments
Closed

Typescript error on filter on GSI #2888

rpostulart opened this issue Sep 18, 2024 · 9 comments

Comments

@rpostulart
Copy link

Environment information

System:
  OS: macOS 14.6.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 65.17 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.8.0 - /usr/local/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.0
  @aws-amplify/backend: 1.2.1
  @aws-amplify/backend-auth: 1.1.4
  @aws-amplify/backend-cli: 1.2.6
  @aws-amplify/backend-data: 1.1.3
  @aws-amplify/backend-deployer: 1.1.2
  @aws-amplify/backend-function: 1.4.0
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.1.1
  @aws-amplify/backend-storage: 1.1.2
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.3.0
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.6
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.2.1
  @aws-amplify/schema-generator: 1.2.2
  aws-amplify: 6.6.0
  aws-cdk: 2.158.0
  aws-cdk-lib: 2.158.0
  typescript: 5.6.2
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1

Describe the bug

 const { data, errors } =
        await client.models.Notification.listNotificationByUserID(
          { userID: userId }, // Changed to false to show unread notifications
          { filter: { statusRead: { eq: true } } }
        );

I get this ts error:

Type '{ statusRead: { eq: true; }; }' is not assignable to type 'ModelFilter<ClientModel<{ CheckoutResponse: ClientCustomType<..., { fields: { statusCode: ModelField<number, never, undefined>; body: ModelField<string, never, undefined>; }; }>; ... 5 more ...; Planning: ClientModel<...>; }, SchemaMetadata<...>, false, SetTypeSubArg<...>, "Notification">>'.
  Type '{ statusRead: { eq: true; }; }' is not assignable to type '{ [x: string]: StringFilter; messageID?: StringFilter; userID?: StringFilter; title?: StringFilter; message?: StringFilter; ... 4 more ...; readonly updatedAt?: StringFilter; }'.
    Property 'statusRead' is incompatible with index signature.
      Type '{ eq: true; }' is not assignable to type 'StringFilter'.
        Types of property 'eq' are incompatible.
          Type 'boolean' is not assignable to type 'string'.ts(2322)
index.d.ts(281, 5): The expected type comes from property 'filter' which is declared here on type '{ filter?: ModelFilter<ClientModel<{ CheckoutResponse: ClientCustomType<..., { fields: { statusCode: ModelField<number, never, undefined>; body: ModelField<string, never, undefined>; }; }>; ... 5 more ...; Planning: ClientModel<...>; }, SchemaMetadata<...>, false, SetTypeSubArg<...>, "Notification">>; ... 6 more ......'

this is the model:


Notification: a
    .model({
      messageID: a.id().required(),
      userID: a.id().required(),
      title: a.string().required(),
      message: a.string().required(),
      timestamp: a.string().required(),
      statusRead: a.boolean().required(),
    })
    .identifier(["messageID"])
    .secondaryIndexes((index) => [index("userID")])
    .authorization((allow) => [allow.ownerDefinedIn("userID")]),

Reproduction steps

run tsc

@ykethan
Copy link
Member

ykethan commented Sep 19, 2024

Hey, thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend Sep 19, 2024
@rpostulart
Copy link
Author

any update, I would like to proceed

@chrisbonifacio
Copy link
Member

chrisbonifacio commented Sep 24, 2024

@rpostulart can you try deleting your node_modules and package-lock.json file, and then upgrade your @aws-amplify/backend, @aws-amplify/backend-cli packages to the latest versions?

Let us know if that helps at all

If that doesn't help, please share the version of @aws-amplify/data-schema in your package-lock.json file. You can also find it by running:

npm list @aws-amplify/data-schema

@chrisbonifacio chrisbonifacio added pending-community-response Issue is pending a response from the author or community. and removed pending-triage labels Sep 24, 2024
@chrisbonifacio chrisbonifacio self-assigned this Sep 24, 2024
@rpostulart
Copy link
Author

rpostulart commented Sep 27, 2024

There error is still there

├─┬ @aws-amplify/[email protected]
│ └── @aws-amplify/[email protected]
└─┬ [email protected]
  └─┬ @aws-amplify/[email protected]
    └─┬ @aws-amplify/[email protected]
      └── @aws-amplify/[email protected] deduped
      
      

it is there twice, is that an issue?

@rpostulart
Copy link
Author

@chrisbonifacio any help on this would be appreciated :)

@chrisbonifacio
Copy link
Member

Hey! Apologies for the delay. It shouldn't be an issue that it's listed twice.

You can upgrade it to the latest version by running:

npm update @aws-amplify/data-schema

This should bump it up to 1.10.0.

You may also have to restart your TS server or reinstall all dependencies for changes to take effect in your IDE.

Let me know if that helps!

@rpostulart
Copy link
Author

"name": "@aws-amplify/data-schema",
"version": "1.10.0",

I am on that version now, restarted the server and also reinstalled all dependencies.
The issue is still the same.

@chrisbonifacio chrisbonifacio added the to-be-reproduced Pending reproduction label Oct 21, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Nov 18, 2024

Hi @rpostulart apologies for the delay. Unfortunately, I was not able to reproduce the issue described in this issue.

I deployed the same schema and created a Notification with my userID
CleanShot 2024-11-18 at 16 32 07@2x

When attempting to query for the Notification by userID, the expected result of the record created in the previous step was returned. I did not encounter a TypeScript error at build time or runtime.
CleanShot 2024-11-18 at 16 34 54@2x

here are the versions of amplify packages and TypeScript i used to reproduce the issue:

"@aws-amplify/backend": "^1.7.0",
"@aws-amplify/backend-cli": "^1.4.2",
"@aws-amplify/data-schema": "1.14.2",
"typescript": "^5.3.3"

@chrisbonifacio chrisbonifacio closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2024
@chrisbonifacio chrisbonifacio removed the pending-community-response Issue is pending a response from the author or community. label Nov 18, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@chrisbonifacio chrisbonifacio removed the to-be-reproduced Pending reproduction label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants