amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Typescript error on filter on GSI

Open rpostulart opened this issue 1 year ago • 1 comments

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

rpostulart avatar Sep 18 '24 20:09 rpostulart

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

ykethan avatar Sep 19 '24 14:09 ykethan

any update, I would like to proceed

rpostulart avatar Sep 24 '24 17:09 rpostulart

@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 avatar Sep 24 '24 18:09 chrisbonifacio

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 avatar Sep 27 '24 08:09 rpostulart

@chrisbonifacio any help on this would be appreciated :)

rpostulart avatar Oct 08 '24 19:10 rpostulart

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!

chrisbonifacio avatar Oct 14 '24 15:10 chrisbonifacio

"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.

rpostulart avatar Oct 15 '24 19:10 rpostulart

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 avatar Nov 18 '24 21:11 chrisbonifacio

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.

github-actions[bot] avatar Nov 18 '24 21:11 github-actions[bot]