All files / src utils.ts

84.62% Statements 11/13
100% Branches 0/0
66.67% Functions 4/6
84.62% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 494x                         4x           2x 8x           8x   2x         4x       26x 216x           216x   26x    
export function defineProperies<
	T extends object,
	P extends PropertyDescriptorMap,
>(obj: T, props: P) {
	Object.defineProperties(obj, props);
	return obj as (T & {
		[K in keyof P]: P[K]['get'] extends unknown
			? ReturnType<NonNullable<P[K]['get']>>
			: P[K]['value']
		;
	});
}
 
export function defineGetters<
	T extends object,
	P extends {
		[key:string]: () => any;
	},
>(obj: T, props: P) {
	Object.defineProperties(obj, Object.keys(props).reduce((map, key) => {
		map[key] = {
			get: props[key],
			set: (_) => {},
			enumerable: true,
			configurable: false,
		};
		return map;
	}, {} as PropertyDescriptorMap));
	return obj as (T & {
		[K in keyof P]: ReturnType<P[K]>;
	});
}
 
export function defineStaticProperies<
	T extends object,
	P extends {[key:string]: any},
>(obj: T, props: P) {
	Object.defineProperties(obj, Object.keys(props).reduce((map, key) => {
		map[key] = {
			value: props[key],
			enumerable: false,
			writable: false,
			configurable: false,
		};
		return map;
	}, {} as PropertyDescriptorMap));
	return obj as (T & P);
}