face-api/src/factories/WithAge.ts

18 lines
334 B
TypeScript
Raw Normal View History

2020-08-18 13:54:53 +02:00
export type WithAge<TSource> = TSource & {
age: number
}
export function isWithAge(obj: any): obj is WithAge<{}> {
2020-12-23 17:26:55 +01:00
return typeof obj.age === 'number';
2020-08-18 13:54:53 +02:00
}
export function extendWithAge<
TSource
2020-12-23 17:26:55 +01:00
>(
2020-08-18 13:54:53 +02:00
sourceObj: TSource,
2020-12-23 17:26:55 +01:00
age: number,
2020-08-18 13:54:53 +02:00
): WithAge<TSource> {
2020-12-23 17:26:55 +01:00
const extension = { age };
return { ...sourceObj, ...extension };
}