alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
10 lines (9 loc) • 610 B
TypeScript
import { IsStrictlyAny, ObjectUnion } from 'alinea/core/util/Types.js';
import { Expr } from './Expr.js';
type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
type FieldsOf<Row> = [Row] extends [Record<string, any>] ? keyof Row extends never ? Expr<object> : {
[K in keyof Row]-?: Field<Row[K]>;
} : never;
export type Fields<T> = IsStrictlyAny<T> extends true ? any : [T] extends [object] ? FieldsOf<T> : Field<T>;
export {};