From 54feda404aef1bf5413e8224a3b0987303a75270 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 17 Jul 2025 10:05:50 -0600 Subject: [PATCH] update type checking --- .../src/organization/organization.types.ts | 11 ++++++++-- .../src/type-utilities/isEqual.ts | 21 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/server-shared/src/organization/organization.types.ts b/packages/server-shared/src/organization/organization.types.ts index 3ff3b00a7..9360b8c99 100644 --- a/packages/server-shared/src/organization/organization.types.ts +++ b/packages/server-shared/src/organization/organization.types.ts @@ -1,8 +1,12 @@ import type { organizations } from '@buster/database'; import { z } from 'zod'; -import type { IsEqual } from '../type-utilities'; import { OrganizationRoleSchema } from './roles.types'; +export const OrganizationColorPaletteSchema = z.object({ + id: z.string(), + color: z.array(z.string()), +}); + export const OrganizationSchema = z.object({ id: z.string(), name: z.string(), @@ -14,8 +18,11 @@ export const OrganizationSchema = z.object({ domains: z.array(z.string()).nullable(), restrictNewUserInvitations: z.boolean(), defaultRole: OrganizationRoleSchema, + organizationColorPalettes: z.array(OrganizationColorPaletteSchema), }); export type Organization = z.infer; -type _DBEqualityCheck = IsEqual; +// Type equality check - this will cause a compilation error if types don't match +const _organizationTypeCheck: Organization = {} as typeof organizations.$inferSelect; +const _databaseTypeCheck: typeof organizations.$inferSelect = {} as Organization; diff --git a/packages/server-shared/src/type-utilities/isEqual.ts b/packages/server-shared/src/type-utilities/isEqual.ts index ab4007bbd..6deeed9d4 100644 --- a/packages/server-shared/src/type-utilities/isEqual.ts +++ b/packages/server-shared/src/type-utilities/isEqual.ts @@ -2,9 +2,22 @@ IsEqual is a type utility that checks if two types are equal. It's used to ensure that a database type is equal to a type. Like when we have a type that is a database type and we want to ensure that it's equal to the schema we have. -Example: -type _DBEqualityCheck = IsEqual; // This will cause a compile error if Organization and organizations.$inferSelect don't match. +RECOMMENDED USAGE (more reliable): +Instead of using IsEqual, use variable assignments for better error messages: -This will cause a compile error if Organization and OrganizationDB don't match. +// Type equality check - this will cause a compilation error if types don't match +const _organizationTypeCheck: Organization = {} as typeof organizations.$inferSelect; +const _databaseTypeCheck: typeof organizations.$inferSelect = {} as Organization; + +This approach provides: +- Clearer error messages +- Better TypeScript error reporting +- More reliable type checking */ -export type IsEqual = [T] extends [U] ? ([U] extends [T] ? true : false) : false; + +// Legacy type equality checker (variable assignment approach is recommended) +type StrictEqual = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 + ? true + : never; + +export type IsEqual = StrictEqual;