Prettify DML properties when inferred (#7937)

This commit is contained in:
Harminder Virk
2024-07-04 12:24:07 +05:30
committed by GitHub
parent b3e55bfa48
commit aa0390af4b
2 changed files with 10 additions and 3 deletions

View File

@@ -10,6 +10,13 @@ import {
import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder"
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations"
/**
* Prettify complex types to a flat object structure
*/
export type Prettify<T> = {
[K in keyof T]: T[K]
} & {}
/**
* Utility type used to remove some optional attributes (coming from K) from a type T
*/

View File

@@ -1,4 +1,4 @@
import { CamelCase } from "../common"
import { CamelCase, Prettify } from "../common"
/**
* Symbol to identify a DML entity from an object
@@ -187,7 +187,7 @@ export type InferManyToManyFields<Relation> = InferHasManyFields<Relation>
* Inferring the types of the schema fields from the DML
* entity
*/
export type InferSchemaFields<Schema extends DMLSchema> = {
export type InferSchemaFields<Schema extends DMLSchema> = Prettify<{
[K in keyof Schema]: Schema[K] extends RelationshipType<any>
? Schema[K]["type"] extends "belongsTo"
? InferBelongsToFields<Schema[K]["$dataType"]>
@@ -199,7 +199,7 @@ export type InferSchemaFields<Schema extends DMLSchema> = {
? InferManyToManyFields<Schema[K]["$dataType"]>
: never
: Schema[K]["$dataType"]
}
}>
/**
* Helper to infer the schema type of a DmlEntity