From 93333c702d8d4a267bb55031ae8554783f5241db Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Sun, 10 Mar 2024 17:00:49 -0400 Subject: [PATCH] fix(types): use Simplify in TIntersect for better type readability The intersection object types is lazily resolved by TypeScript until the type is mapped and intersected with an empty object, I guess. Not really sure why it works that way, but doing this leads to a nicer DX (screenshots included in the PR). --- src/type/intersect/intersect-type.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/type/intersect/intersect-type.ts b/src/type/intersect/intersect-type.ts index 1b1f6a5d..f62aa933 100644 --- a/src/type/intersect/intersect-type.ts +++ b/src/type/intersect/intersect-type.ts @@ -30,6 +30,8 @@ import type { TSchema, SchemaOptions } from '../schema/index' import type { Static } from '../static/index' import { Kind } from '../symbols/index' +type Simplify = {} & { [P in keyof T]: T[P] } + // ------------------------------------------------------------------ // IntersectStatic // ------------------------------------------------------------------ @@ -50,7 +52,7 @@ export interface IntersectOptions extends SchemaOptions { // prettier-ignore export interface TIntersect extends TSchema, IntersectOptions { [Kind]: 'Intersect' - static: TIntersectStatic + static: Simplify> type?: 'object' allOf: [...T] }