Skip to content

Commit

Permalink
Adds type tests, fixes lacking imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tywalch committed Jan 24, 2025
1 parent acd8e98 commit 4e3322d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2937,7 +2937,7 @@ export class ElectroError<E extends Error = Error> extends Error {
readonly date: number;
readonly cause: E | undefined;
readonly isElectroError: boolean;
readonly params: () => Record<string, unknown> | null;
readonly params: <T = Record<string, unknown>>() => T | null;
readonly ref: {
readonly code: number;
readonly section: string;
Expand Down
10 changes: 10 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T extends Function | string | number | boolean
? T
: { [Key in keyof T]: Resolve<T[Key]> };
Expand Down
2 changes: 1 addition & 1 deletion src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class Entity {
Object.defineProperty(err, '__edb_params', {
enumerable: false,
value: params,
})
});
err.__isAWSError = true;
throw err;
});
Expand Down
19 changes: 17 additions & 2 deletions test/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -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> = T extends Function | string | number | boolean
? T
Expand Down Expand Up @@ -149,3 +150,17 @@ expectType<{
}>(get<EntityWithSKEntityItem>());

expectType<{ supposedly: "can" }>(get<EntitySchema>());

const error = new ElectroError('test');

expectAssignable<{
params: () => Record<string, unknown> | null;
}>(error);

const defaultErrorParams = error.params();

expectType<Record<string, unknown> | null>(defaultErrorParams);

const queryErrorParams = error.params<QueryCommandOutput>();

expectType<QueryCommandOutput | null>(queryErrorParams);
2 changes: 1 addition & 1 deletion test/v2response.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ entityOne
.delete({ prop1, prop2, prop4 })
.go()
.then((res) => {
expectType<string>(res.data.prop1);
expectType<string | undefined>(res.data?.prop1);
});

entityOne
Expand Down

0 comments on commit 4e3322d

Please sign in to comment.