feat(typescript-types): Add Simplify<T, E, I>
This commit is contained in:
3
packages/typescript-types/src/built-ins.ts
Normal file
3
packages/typescript-types/src/built-ins.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { Primitive } from './primitive.js'
|
||||
|
||||
export type BuiltIns = Primitive | void | Date | RegExp
|
||||
3
packages/typescript-types/src/non-container-type.ts
Normal file
3
packages/typescript-types/src/non-container-type.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { BuiltIns } from './built-ins.js'
|
||||
|
||||
export type NonContainerType = BuiltIns | Function | (new (...arguments_: any[]) => unknown)
|
||||
1
packages/typescript-types/src/primitive.ts
Normal file
1
packages/typescript-types/src/primitive.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type Primitive = null | undefined | string | number | boolean | symbol | bigint | PropertyKey
|
||||
9
packages/typescript-types/src/simplify.ts
Normal file
9
packages/typescript-types/src/simplify.ts
Normal 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
|
||||
Reference in New Issue
Block a user