Skip to content

Commit

Permalink
Merge pull request #51 from dsdavis4/fix_type_of_array_includes
Browse files Browse the repository at this point in the history
Fix type of array includes
  • Loading branch information
dsdavis4 authored Oct 9, 2024
2 parents 123caff + c76b67a commit 6f41c7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "dyna-record",
"version": "0.1.1",
"version": "0.1.2",
"description": "Typescript Object Relational Mapper (ORM) for Dynamo",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"test:watch": "jest --watch",
"eslint": "npx eslint . --ext .ts",
"eslint-fix": "npx eslint . --ext .ts --fix",
"prettier": "npx prettier . --write",
Expand Down
2 changes: 1 addition & 1 deletion src/operations/FindById/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type EntityKeysWithIncludedAssociations<
[K in P]: T[K] extends DynaRecord
? EntityAttributes<T>
: T[K] extends DynaRecord[]
? Array<EntityAttributes<T>>
? Array<EntityAttributes<T[K][number]>>
: T[K];
};

Expand Down
6 changes: 6 additions & 0 deletions tests/integration/FindById.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,12 @@ describe("FindById", () => {
if (phoneBook !== undefined) {
// @ts-expect-no-error: included HasMany relationships will be an array
Logger.log(phoneBook.addresses.length);

// @ts-expect-error: included HasMany relationships do not have attributes of the parent class instance
Logger.log(phoneBook.addresses.some(address => address.edition));

// @ts-expect-no-error: included HasMany relationships only have attributes of the included relationship entity class instance
Logger.log(phoneBook.addresses.some(address => address.homeId));
}
});
});
Expand Down

0 comments on commit 6f41c7f

Please sign in to comment.