refactor: Improve hydration type handling with Omit and preserve original properties

This commit is contained in:
2025-02-15 12:14:07 -06:00
parent 69f32aa067
commit 211c1ca4c6
+5 -5
View File
@@ -9,8 +9,8 @@ import type { Client } from "./client";
export type GatewayObject = Message | Channel;
export type Hydrateable = Context | GatewayObject
export type Hydrated<T extends Hydrateable, K extends Array<Expectation>> =
T extends Message ? HydratedMessage<K> & Partial<HydratedMessage<Expectation[]>> :
T extends Context ? HydratedContext<K> & Partial<HydratedContext<Expectation[]>> : never;
T extends Message ? HydratedMessage<K> & Omit<T, keyof HydratedMessage<K>> :
T extends Context ? HydratedContext<K> & Omit<T, keyof HydratedContext<K>> : never;
/**
* Hydrates a given data object based on the provided expectations.
@@ -70,10 +70,10 @@ export async function hydrate<T extends Hydrateable, K extends Array<Expectation
}
// Create a new object that preserves all existing properties
const result = { ...data };
const result = { ...data } as any;
// Return with both previous and new hydrated properties preserved
return result as Hydrated<T, K>;
// Ensure the result is properly typed with both old and new hydrated properties
return result as T & Hydrated<T, K>;
}
/**