UNPKG

kitcn

Version:

kitcn - React Query integration and CLI tools for Convex

42 lines 1.84 kB
//#region src/internal/types.d.ts /** * Filter object type to only known keys from reference type. * Pattern from Drizzle ORM: drizzle-orm/src/utils.ts:151-156 * * Prevents extra properties from widening inferred types. * * @example * type Config = { name: string; age: number }; * type Input = { name: string; age: number; extra: boolean }; * type Filtered = KnownKeysOnly<Input, Config>; // { name: string; age: number } * @public */ type KnownKeysOnly<T, K> = { [P in keyof T]: P extends keyof K ? T[P] : never }; /** * Narrow a type to an expected shape without losing inference. * Pattern from Drizzle ORM: drizzle-orm/src/utils.ts * @public */ type Assume<T, U> = T extends U ? T : U; /** * Extract return type if function, otherwise use the value type. * Pattern from Drizzle ORM: drizzle-orm/src/relations.ts * @public */ type ReturnTypeOrValue<T> = T extends ((...args: any[]) => infer R) ? R : T; /** * Simplify complex type intersections for better IDE display. * Pattern from Drizzle ORM: The & {} intersection "seals" the type to prevent * distributive conditional behavior that can cause union widening. * @see https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/utils.ts#L144-L149 */ type Simplify<TType> = TType extends any[] | Date ? TType : { [K in keyof TType]: TType[K] } & {}; /** * Omit keys without removing a potential union. * Unlike standard Omit, this preserves union types. */ type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never; /** Makes the object recursively optional */ type DeepPartial<TObject> = TObject extends object ? { [P in keyof TObject]?: DeepPartial<TObject[P]> } : TObject; //#endregion export { ReturnTypeOrValue as a, KnownKeysOnly as i, DeepPartial as n, Simplify as o, DistributiveOmit as r, Assume as t };