Skip to content
Discussion options

You must be logged in to vote

Resolved

import type { SQL } from 'drizzle-orm';
import type { PgColumn } from 'drizzle-orm/pg-core';

type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};

type SelectedDTOType = Record<string, SQL | PgColumn>;

export type DtoFields<
  DTO extends SelectedDTOType,
  IsNestedNullable extends boolean = true,
> = Simplify<{
  [Key in keyof DTO]: DTO[Key] extends {
    _: { brand: 'Column'; data: infer ColumnType; notNull: infer RequiredColumn };
  }
    ? RequiredColumn extends true
      ? ColumnType
      : ColumnType | null
    : DTO[Key] extends { _: { brand: 'SQL'; type: infer SQLType } }
      ? SQLType
      : DTO[Key] extends SelectedDTOType
        ? IsNestedNullable extend…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by nisharg-codal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant