From 4e3322dee9a22f7e27aa2e79f6c386fc9cc671dc Mon Sep 17 00:00:00 2001 From: ty walch Date: Fri, 24 Jan 2025 15:08:17 -0500 Subject: [PATCH] Adds type tests, fixes lacking imports --- index.d.ts | 2 +- index.test-d.ts | 10 ++++++++++ src/entity.js | 2 +- test/types.test-d.ts | 19 +++++++++++++++++-- test/v2response.test-d.ts | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 65ee3d30..472d653d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2937,7 +2937,7 @@ export class ElectroError extends Error { readonly date: number; readonly cause: E | undefined; readonly isElectroError: boolean; - readonly params: () => Record | null; + readonly params: >() => T | null; readonly ref: { readonly code: number; readonly section: string; diff --git a/index.test-d.ts b/index.test-d.ts index 95a09f55..37e0ac83 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -14,6 +14,16 @@ import { expectNotAssignable, } from "tsd"; +import * as typeTestsTypes from './test/types.test-d'; +import * as typeTestsUpsert from './test/upsert.test-d'; +import * as typeTestsV2response from './test/v2response.test-d'; +import * as typeTestsQueries from './test/queries.test-d'; +import * as typeTestsSchema from './test/schema.test-d'; +import * as typeTestsTests from './test/tests.test-d'; +import * as typeTestsWhere from './test/where.test-d'; +import * as typeTestsEntity from './test/entity.test-d'; +import * as typeTestsIndexes from './test/indexes.test-d'; + type Resolve = T extends Function | string | number | boolean ? T : { [Key in keyof T]: Resolve }; diff --git a/src/entity.js b/src/entity.js index 6e314c60..318cc701 100644 --- a/src/entity.js +++ b/src/entity.js @@ -522,7 +522,7 @@ class Entity { Object.defineProperty(err, '__edb_params', { enumerable: false, value: params, - }) + }); err.__isAWSError = true; throw err; }); diff --git a/test/types.test-d.ts b/test/types.test-d.ts index d8432ebb..f4f0f6b3 100644 --- a/test/types.test-d.ts +++ b/test/types.test-d.ts @@ -1,5 +1,6 @@ -import { expectType } from "tsd"; -import { Entity, EntityItem } from "../"; +import { expectType, expectAssignable } from "tsd"; +import { Entity, EntityItem, ElectroError } from "../"; +import { QueryCommandOutput } from '@aws-sdk/client-dynamodb'; export type Resolve = T extends Function | string | number | boolean ? T @@ -149,3 +150,17 @@ expectType<{ }>(get()); expectType<{ supposedly: "can" }>(get()); + +const error = new ElectroError('test'); + +expectAssignable<{ + params: () => Record | null; +}>(error); + +const defaultErrorParams = error.params(); + +expectType | null>(defaultErrorParams); + +const queryErrorParams = error.params(); + +expectType(queryErrorParams); \ No newline at end of file diff --git a/test/v2response.test-d.ts b/test/v2response.test-d.ts index 7f3d1728..f335492d 100644 --- a/test/v2response.test-d.ts +++ b/test/v2response.test-d.ts @@ -166,7 +166,7 @@ entityOne .delete({ prop1, prop2, prop4 }) .go() .then((res) => { - expectType(res.data.prop1); + expectType(res.data?.prop1); }); entityOne