Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/ana_utils/src/utils.ts>applyDefaults

🅰️ Utility functions for Ana
Go to Latest
function applyDefaults
import { applyDefaults } from "https://deno.land/x/ana_utils@v0.0.1/src/utils.ts";

Inside Ana, there are interfaces that start with a lowercase i, e.g. iAnaConfiguration. These are input interfaces and have the same properties as their equivalent without the i. So then, what is the difference between each other? All of the properties of an input interface must be optional. Because we can't force the developer to input all properties of a interface every time. In other words, if a developer wants to configure Ana, it shouldn't be a requirement to add all AnaConfiguration properties only to change one of them.

Then, the problem happens when trying to use the input interface. All values are optional, so it becomes verbose to validate each and everyone of them in a way simmilar to this: interface.property ? interface.property : undefined. That's why we need the second non-input interface, where no property is optional. This function transforms iExample into Example using the default values found in dExample.

Type Parameters

Type extends { }
iType extends { }

Parameters

defaultParameters: Type

To transofrm an input interface into a non-input interface, one needs an Object with default values.

inputParameters: iType

The set properties of the input interface.

Returns

An object of a non-input interface overwritten with input property values.