feat(typescript-types): Add Simplify<T, E, I>

This commit is contained in:
T. R. Bernstein
2025-07-15 11:19:43 +02:00
parent 9700b7d46d
commit 2aa71d91e4
6 changed files with 78 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
import type { Primitive } from './primitive.js'
export type BuiltIns = Primitive | void | Date | RegExp

View File

@@ -0,0 +1,3 @@
import type { BuiltIns } from './built-ins.js'
export type NonContainerType = BuiltIns | Function | (new (...arguments_: any[]) => unknown)

View File

@@ -0,0 +1 @@
export type Primitive = null | undefined | string | number | boolean | symbol | bigint | PropertyKey

View File

@@ -0,0 +1,9 @@
import type { NonContainerType } from './non-container-type.js'
export type Simplify<T, Exclude = NonContainerType, Include = object> = T extends Exclude
? T
: T extends Include
? {
[K in keyof T]: Simplify<T[K], Exclude, Include>
}
: T