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
88 stars 76 forks source link

Typescript error on filter on GSI #2888

Open rpostulart opened 3 days ago

rpostulart commented 3 days ago

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 commented 2 days ago

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