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

[BUG] Impossible add element to array #1614

Open
6 tasks done
ksimonm opened this issue Jul 4, 2023 · 0 comments
Open
6 tasks done

[BUG] Impossible add element to array #1614

ksimonm opened this issue Jul 4, 2023 · 0 comments

Comments

@ksimonm
Copy link

ksimonm commented Jul 4, 2023

Summary:

Impossible add element to array

Object literal may only specify known properties, and '$ADD' does not exist in type 'Partial<MyItem>'.

await MyTable.update({ PK }, { $ADD: { arr: [arrItem] } });

Code sample:

Schema

    {
        PK: {
            type: String,
            hashKey: true,
        },
        arr: {
            type: Array,
            schema: [String],
        },
    }

Model

import * as dynamoose from 'dynamoose';
import { Item } from 'dynamoose/dist/Item';

class MyItem extends Item {
    PK: string;
    arr: string[];
}

const schema = new dynamoose.Schema(
    {
        PK: {
            type: String,
            hashKey: true,
        },
        arr: {
            type: Array,
            schema: [String],
        },
    }
);

const MyTable = dynamoose.model<MyItem>('MyTable', schema, { create: false });

export { MyTable };

General

await MyTable.update({ PK }, { $ADD: { arr: [arrItem] } });

Current output and behavior (including stack trace):

/node/lib/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
DynamoRep.ts:43:57 - error TS2769: No overload matches this call.
  Overload 1 of 18, '(obj: Partial<MyItem>, callback: CallbackType<MyItem, any>): void', gave the following error.
    Argument of type '{ $ADD: { arr: string[]; }; }' is not assignable to parameter of type 'CallbackType<MyItem, any>'.
      Object literal may only specify known properties, and '$ADD' does not exist in type 'CallbackType<MyItem, any>'.
  Overload 2 of 18, '(keyObj: InputKey, updateObj: Partial<MyItem>): Promise<MyItem>', gave the following error.
    Argument of type '{ $ADD: { arr: string[]; }; }' is not assignable to parameter of type 'Partial<MyItem>'.
      Object literal may only specify known properties, and '$ADD' does not exist in type 'Partial<MyItem>'.
  Overload 3 of 18, '(keyObj: ObjectType, updateObj: Partial<MyItem>): Promise<MyItem>', gave the following error.
    Argument of type '{ $ADD: { arr: string[]; }; }' is not assignable to parameter of type 'Partial<MyItem>'.
      Object literal may only specify known properties, and '$ADD' does not exist in type 'Partial<MyItem>'.

43         await MyTable.update({ PK }, { $ADD: { arr: [arrItem] } });
                                              ~~~~~~~~~~~~~~~~~~~~~~


    at createTSError (/node/lib/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/node/lib/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (//node/lib/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/node/lib/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/node/lib/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (/node/lib/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19) {
  diagnosticCodes: [ 2769 ]
}

Expected output and behavior:

Environment:

Operating System:
Operating System Version:
Node.js version (node -v):
NPM version: (npm -v):
Dynamoose version:

Other information (if applicable):

I can remove the generic. But this creates many other problems.

const MyTable = dynamoose.model('MyTable', schema, { create: false });

or

add "$ADD" to type :)

class MyItem extends Item {
    PK: string;
    arr: string[];
    "$ADD": unknown;
}

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
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

1 participant