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