Overview
Bunli includes a collection of advanced TypeScript type utilities inspired by TanStack Router. These utilities enable complex type manipulations, type inference, and type safety throughout the framework. Location:packages/core/src/utils/type-helpers.ts
Union and Intersection Types
UnionToIntersection<T>
Converts a union type to an intersection type.
Constraint Types
Constrain<T, TConstraint, TDefault>
Constrains a type to a specific constraint, with optional default fallback.
Property Selection
PickRequired<T>
Picks only required (non-optional) properties from a type.
PickOptional<T>
Picks only optional properties from a type.
PickAsRequired<TValue, TKey>
Converts specified optional properties to required.
Primitive and Object Extraction
ExtractPrimitives<TUnion>
Extracts primitive types from a union.
ExtractObjects<TUnion>
Extracts object types from a union.
Merging Types
MergeAll<TUnion>
Merges all types in a union into a single type.
PartialMergeAll<TUnion>
Merges types with all properties optional.
Assign<TLeft, TRight>
Assigns properties from right type to left type, similar to Object.assign().
Type Inference Control
NoInfer<T>
Prevents type inference for a generic parameter.
Type Checks
IsAny<TValue, TYesResult, TNoResult>
Checks if a type is any.
IsUnion<T>
Checks if a type is a union type.
IsNonEmptyObject<T>
Checks if a type is a non-empty object.
Utility Types
WithoutEmpty<T>
Removes empty object types from a union.
Expand<T>
Expands a type for better IntelliSense display.
DeepPartial<T>
Makes all properties and nested properties optional.
Advanced Patterns
MakeDifferenceOptional<TLeft, TRight>
Makes properties that exist in both types optional in the right type.
IntersectAssign<TLeft, TRight>
Assigns properties using intersection instead of overwrite.
Usage in Bunli
These type helpers are used internally throughout Bunli for:- Plugin store merging: Combining multiple plugin stores with
MergeAll - Type inference: Using
NoInferto control generic inference - Command options: Using
PickRequiredandPickOptionalfor option types - Configuration: Using
DeepPartialfor config overrides
See Also
- Plugin API - Plugin system using these type helpers
- Command API - Command types and inference
- TypeScript Handbook - Advanced type manipulation