Combining Default and Custom Options in Typescript | Task

Ole Ersoy
Nov - 01  -  1 min

Scenario

We have a RANGE_DEFAULT_OPTIONS object:

const RANGE_DEFAULT_OPTIONS = { min: 0, max: 100 }

And we want to use the defaults unless the API overrides them:

export function range(value:number, options:any) {
   ...
}

Approach

options = { ...RANGE_DEFAULT_OPTIONS, ...options }

Demo