/** @public */ export type InitFunc = (this: O) => T; /** * Define property on target, call init it when first use, them memorize * @public */ export function initOnRead(target: any, propertyKey: T, init: InitFunc) { if (Object.hasOwn(target, propertyKey)) { return; } Object.defineProperty(target, propertyKey, { configurable: true, get: function (): O[T] { const data = init.call(this); delete target[propertyKey]; target[propertyKey] = data; return data; }, set(v: T) { delete target[propertyKey]; target[propertyKey] = v; }, }); }