This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const shallowMerge = <T extends object = Record<string, any>>( | |
...objects: T[] | |
): T => { | |
return objects.reduce((prev, cur) => ({ ...prev, ...cur }), {} as T); | |
}; | |
export const deepMerge = <T extends object = Record<string, any>>( | |
target: T, | |
...sources: object[] | |
): T => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const humanReadableList = ( | |
array: unknown[], | |
join: ',' | ';' = ',', | |
finalJoin = 'and', | |
): string => { | |
if (!Array.isArray(array) || array.length == 0) return ''; | |
if (array.length == 1) return String(array[0]); | |
const arr = array.slice(0), | |
last = arr.pop(); | |
return array.length > 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type DeepPartial<T> = T extends Function | |
? T | |
: T extends object | |
? { [P in keyof T]?: DeepPartial<T[P]> | undefined } | |
: T | undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FoodItem { | |
constructor(private opts: FoodProperties) {} | |
public get<T extends keyof FoodProperties>(property: T): FoodProperties[T] { | |
return this.opts[property]; | |
} | |
public change<T extends keyof FoodProperties>( | |
property: T, | |
value: FoodProperties[T] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FoodProperties = { | |
name: string; | |
description: string; | |
price: number; | |
section: "breakfast" | "lunch" | "dinner" | "dessert"; | |
}; | |
class FoodItem { | |
constructor(private opts: FoodProperties) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FoodProperties = { | |
name: string; | |
description: string; | |
price: number; | |
section: "breakfast" | "lunch" | "dinner" | "dessert"; | |
}; | |
class FoodItem { | |
constructor(private opts: FoodProperties) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Drink { | |
name: string; | |
price: number; | |
ounces: number; | |
} | |
class Food { | |
name: string; | |
price: number; | |
type: "appetizer" | "entree"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isAsyncCallback = (func: Function): boolean => { | |
return ( | |
func.constructor.name == 'AsyncFunction' || | |
types.isAsyncFunction(func) || | |
func.toString().indexOf('__awaiter(') > 0 | |
); | |
}; |