Skip to content

Commit 4c5284f

Browse files
committed
chore(json-api-nestjs): Fix types
1 parent 1b61fb3 commit 4c5284f

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

libs/json-api/json-api-nestjs/src/lib/helper/orm/orm-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EntityProps,
88
EntityPropsArray,
99
EntityRelation,
10+
IsArray,
1011
TypeCast,
1112
TypeOfArray,
1213
UnionToTuple,
@@ -79,7 +80,7 @@ export enum TypeField {
7980
export type TypeForId = Extract<TypeField, TypeField.number | TypeField.string>;
8081

8182
export type FieldWithType<E extends Entity> = {
82-
[K in EntityProps<E>]: E[K] extends unknown[]
83+
[K in EntityProps<E>]: IsArray<E[K]> extends true
8384
? TypeField.array
8485
: E[K] extends Date
8586
? TypeField.date

libs/json-api/json-api-nestjs/src/lib/mixin/service/typeorm-utils.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ export class TypeormUtilsService<E extends Entity> {
243243
const paramsName = this.getParamName(fieldWithAlias);
244244

245245
if (!isTargetField(this._relationFields, fieldName)) {
246-
247246
if (
248247
(operand === FilterOperand.ne || operand === FilterOperand.eq) &&
249248
(valueConditional === 'null' || valueConditional === null)
@@ -525,7 +524,7 @@ export class TypeormUtilsService<E extends Entity> {
525524
)) {
526525
const [props, type] = ObjectTyped.entries(item)[0];
527526
if (type !== null) {
528-
target[props] = type;
527+
target[props] = type as any;
529528
} else {
530529
target[props] = null as any;
531530
}

libs/json-api/json-api-nestjs/src/lib/types/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,4 @@ export type JSONValue =
6161
| { [x: string]: JSONValue }
6262
| Array<JSONValue>;
6363

64-
export type IsArray<T> = T extends unknown[] ? true : false;
65-
66-
export type IsPropertyIsArray<E, P extends EntityProps<E>> = IsArray<E[P]>;
64+
export type IsArray<T> = [Extract<T, unknown[]>] extends [never] ? false : true;

libs/json-api/json-shared-type/src/types/entity-type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type EntityField =
44
| boolean
55
| string[]
66
| number[]
7+
| null
78
| Date;
89

910
export type EntityProps<T> = {

0 commit comments

Comments
 (0)