New Functions
Add mergeOptions function → PR #442
Merge two optional option objects with runtime behavior and TypeScript inference that both understand undefined. mergeOptions shallow-merges two defined objects, lets the second object override overlapping keys, and returns the defined argument when either side is undefined.
- Models
T | undefinedinputs withoutObject.assignworkarounds - Preserves optional properties and required override keys in the result type
- Returns
undefinedwhen both inputs areundefined
import * as _ from 'radashi'
const defaults = { port: 3000, host: 'localhost' }
const userConfig = { port: 8080, ssl: true }
_.mergeOptions(defaults, userConfig)
// => { port: 8080, host: 'localhost', ssl: true }
_.mergeOptions(undefined, userConfig)
// => { port: 8080, ssl: true }
_.mergeOptions(undefined, undefined)
// => undefinedDocs / Source / Tests / Type Tests
New Features
Improve sort return type when sorting a tuple → PR #421
Sorting a tuple now preserves its tuple length in the return type instead of widening the result to a plain array. This keeps tuple-aware inference intact for as const inputs while preserving the same runtime behavior: sort still copies the input and returns a mutable sorted array.
- Regular arrays still return mutable arrays
- Readonly arrays still return mutable arrays
- Const tuples now return a mutable tuple with the same length
import * as _ from 'radashi'
const list = [{ index: 2 }, { index: 0 }, { index: 1 }] as const
const result = _.sort(list, item => item.index)
// type: [(typeof list)[number], (typeof list)[number], (typeof list)[number]]
// => [{ index: 0 }, { index: 1 }, { index: 2 }]Docs / Source / Type Tests